回到之前的GIT提交而不用分叉

时间:2016-02-04 13:39:41

标签: git

我有以下Git日志。我希望回到分支大师之前的2c2996639ec10d659a771c4398759deb323eb08c。但是,我希望保留存储库中最后一次提交的历史记录。最后,我不想创建一个fork,但只想要一个分支。

所以我想我可以做类似的事情:

git checkout 2c2996639ec10d659a771c4398759deb323eb08c

但如果我这样做,那么当我稍后将其推送到存储库时会发生什么?

[Michael@devserver testing]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 43 commits.
#
nothing to commit (working directory clean)
[Michael@devserver testing]$ git log
commit 0fb5d27e1bc57b120e0f361f8f71a947bb264448
Author: Michael Smith <example@gmail.com>
Date:   Thu Feb 4 05:20:31 2016 -0800

    changed to using account to links

commit 2c2996639ec10d659a771c4398759deb323eb08c
Author: Michael Smith <example@gmail.com>
Date:   Mon Feb 1 07:48:20 2016 -0800

    Finished implementation of new projects

......
......

commit 0ad8e4a14f01ccb964b945afaafe98f14f478f98
Author: Michael Smith <example@gmail.com>
Date:   Wed Apr 23 06:21:04 2014 -0700

    Changed link locations to reflect changing /lib/plugins to /lib/plugins_3rd and /lib/plugins_my to /lib/plugins

commit dde33715730c58f100c180d6871251baef0d25ea
Author: Michael Smith <example@gmail.com>
Date:   Mon Apr 21 00:55:52 2014 -0700

    Initial commit
[Michael@devserver testing]$ git log

1 个答案:

答案 0 :(得分:1)

git revert HEAD当您检出最近的提交时,将在您当前的HEAD之上创建一个新提交,撤消其中的更改。这将使代码保持与提交之前相同的状态,但是您的所有历史记录都是完整的。

o  (HEAD) Revert - gets back to state A
|
o  Commit that we want to preserve but undo
|  
o  Last good commit, call it state A
|
|  (previous history)