2010-04-11 88 views
23

当我执行'git pull'时,我与头部提交发生冲突。所以我做了'git rebase --abort'如何删除我在本地git存储库中的上次提交

我可以'保存'我的提交到一个“补丁”,然后做一个git拉?

我想模仿是:

  • 我没有犯,但我做了一个“git的藏匿”,而不是
  • 做一个混帐拉,以避免任何合并错误

所以我需要某种方式来“倒流时钟”。这可能与git?

回答

56

7826b2补丁仍然会引起冲突时,它的拉力后应用,但你可以做到以下几点:

git reset --soft HEAD^ 
git stash 
git pull 
git stash pop # Will cause a conflict 
git commit # Re-commit 7826b2 

另一个工作流,也可以:

git reset --hard HEAD^ 
git pull 
git cherry-pick 7826b2 # Will cause a conflict 

第二个工作流依赖Git保留7826b2在reflog中提交的事实(您可以将其视为回收站),即使您重置第一行引入的更改也是如此。

0

有一个办法,其实在混帐,我敢肯定有做着它的多种方式...

你可以这样做:

git stash  # Stash your changes 
git pull  # Pull the changes 
git stash pop # Pop your stash 

你可以这样做:

git pull --rebase # Bring in the changes and apply yours on top of it. 

你可以这样做:

git stash  # Stash your changes 
git checkout <commit> # Pull a specific commit. 
git stash pop # Pop your stash 

希望它有帮助。

4

如果你没有犯在本地资源库的更改,你可以做一个直底垫:

混帐取起源

git的变基原产/主

这解开你的本地从本地主设备提交,应用来自原始/主设备的新提交,然后重播您的本地提交。

在你的情况下,这将导致冲突,git会告诉你哪些文件需要被编辑来解决冲突。这样做后,git add这些文件,然后git commit没有参数重新发送更改。

+0

这就是我一直在寻找因为,太好了。 – 2013-05-14 08:20:50

0

首先,我建议做你的分支的备份:

git branch your_branch_backup 

那么最简单的方法是:

git reset --soft <commit> #Go back in time but without loosing your changes 
git stash     #Stash your changes 
git pull     #Refresh your branch with origin 
git stash pop    #Re-apply your changes on the refreshed branch 

然后你可以提交照常

相关问题