2014-02-19 239 views

回答

0

this post

如果,另一方面,要真正摆脱自那以后,你所做的一切,有两种可能性。一,如果你还没有发表任何这些提交的,简单复位:

# This will destroy any local modifications. 
# Don't do it if you have uncommitted work you want to keep. 
git reset --hard 0d1d7fc32 

# Alternatively, if there's work to keep: 
git stash 
git reset --hard 0d1d7fc32 
git stash pop 
# This saves the modifications, then reapplies that patch after resetting. 
# You could get merge conflicts, if you've modified things which were 
# changed since the commit you reset to 

在另一方面,如果你已经发表的工作,你可能不希望重置分支,因为这是有效的重写历史。在那种情况下,你确实可以恢复提交。使用git,回复具有非常明确的含义:使用反向修补程序创建提交以将其取消。这样你就不会重写任何历史。

# This will create three separate revert commits: 
git revert 0766c053 25eee4ca a867b4af 

# It also takes ranges. This will revert the last two commits: 
git revert HEAD~2..HEAD 

# To get just one, you could use `rebase -i` to squash them afterwards 
# Or, you could do it manually (be sure to do this at top level of the repo) 
# get your index and work tree into the desired state, without changing HEAD: 
git checkout 0d1d7fc32 . 
# and then commit 
git commit # be sure and write a good message describing what you just did 
2

你应该有这样的历史:

A--B--C---D--E  <-- Master 
\  /
    Z--Y--X   <-- Your feature 

你想从主分支中删除承诺d。你只需要恢复这个提交。有一个git命令是:

git revert -m 1 [sha_of_D] 

其中-m意味着提交父数。

它将在master中创建一个新的提交,撤消您的功能分支所做的更改。欲了解更多信息,你可以去the main source

相关问题