[Git] Undo my last commit and split it into two separate ones

When you accidentally committed some changes to your branch you have various possibilities to “undo” that operation and add some more changes. One is to use git amend to change the commit message or add new files. But what we want to take out all of the committed changes again and maybe even split them into separate commits. Let’s see how we can achieve that. Note: This only holds if you did not yet push your changes to the remote repository.

In this case, what we can do is first do the reset:

git reset HEAD~

Then spreate files into diifferent commit messages.

原文地址:https://www.cnblogs.com/Answer1215/p/10603398.html

时间: 2024-08-30 15:51:38

[Git] Undo my last commit and split it into two separate ones的相关文章

undo/delete a commit on git

areful: git reset --hard WILL DELETE YOUR WORKING DIRECTORY CHANGES. Be sure to stash any local changes you want to keep before running this command. Assuming you are sitting on that commit, then this command will wack it... git reset --hard HEAD~1 T

git cherry-pick合并某个commit

git cherry-pick合并某个commit 1.使用方法及其作用 git cherry-pick可以选择某一个分支中的一个或几个commit(s)来进行操作(操作的对象是commit).例如,假设我们有个稳定版本的分支,叫v2.0,另外还有个开发版本的分支v3.0,我们不能直接把两个分支合并,这样会导致稳定版本混乱,但是又想增加一个v3.0中的功能到v2.0中,这里就可以使用cherry-pick了. 就是对已经存在的commit 进行 再次提交: 使用方法如下: git cherry-

使用git rebase合并多次commit

使用git rebase合并多次commit 1. 背景 一个repo通常是由一个team中的多个人共同维护,如果需要增加新feature,那么就是一个feature分支了.由于开发中各种修改,本feature分支多次commit.最后提交master后,会看到乱七八糟的所有增量修改历史.其实对别人来说,我们的改动应该就是增加或者删除,给别人看开发过程的增量反而太乱.于是我们可以将feature分支的提交合并后然后再merge到主干这样看起来就清爽多了. 记得知乎上有个帖子提问为啥vue的作者尤

git undo last commit

$ git commit -m "Something terribly misguided" (1) $ git reset --soft HEAD~ (2) << edit files as necessary >> (3) $ git add ... (4) $ git commit -c ORIG_HEAD (5) 转自: http://stackoverflow.com/questions/927358/how-do-you-undo-the-last-

[Git] Undo a commit that has already been pushed to the remote repository

If we pushed our changes already to the remote repository we have to pay attention to not change the git history (using commands like rebase, reset, amend etc). Other collaborators of the same repository might already have pulled your changes, thus r

Git undo 操作

相比传统的版本管理工具,git 的 undo 操作也不是很简单明了,本文尝试总结常用的 undo 操作. 重新提交 应该避免考虑不周全的提交,但这太难了.因此Git 专门提供了一个命令来弥补粗心的提交导致的问题.说白了就是让你重新提交一次. $ git commit --amend 这个命令会重新提交暂存区中的内容.因此你可以重新考虑哪些文件需要提交,并且把这次提交用的comment准备好. 为了更好的理解这个命令,我们看看它是怎么工作的. 它相当于下面的两条命令: $ git reset --

(转)找回Git中丢失的Commit

总结:更新代码前一定要先将本地修改的文件存到本地git仓库.今天脑残直接更新了远程仓库代码导入今天写的代码...... @[git|commit|reflog] 在使用Git的过程中,有时候会因为一些误操作,比如reset.rebase.merge等.特别是在Commit之后又执行了git reset --hard HEAD强制回滚本地记录以及文件到服务器版本,导致本地做的修改全部恢复到Git当前分支的服务器版本,同时自己的Commmit记录也消失了.碰到这种情况,不要慌,我们在Git上做的任何

git 只merge一个commit的方法

https://git-scm.com/book/tr/v2/Git-Basics-Viewing-the-Commit-History gil log 来查看commit的记录 Other maintainers prefer to rebase or cherry-pick contributed work on top of their master branch, rather than merging it in, to keep a mostly linear history. Wh

将代码库从 SVN 迁移至 Git 并保留所有 commit 记录

公司内部原本使用 SVN 进行版本控制,但随着 Github 的流行我个人的代码管理习惯逐渐转变.虽然公司项目并非开源,SVN 所具有的标准 trunk / branches / tags 结构完全够用,使用 Git 仍然有如下优势: 类似 GitHub 的 GitLab 免费管理工具.将代码托管在自己内部服务器上的同时,提供了优美的 web 界面,图形化分支结构,更直观的代码审查,统计.issue 系统.wiki 等功能全面集成. 更方便主程做 code review,控制代码质量.创建主仓库