在推动它们之后无法压缩git中的提交 - Visual studio

时间:2016-11-07 22:25:48

标签: git visual-studio-2015

我正在使用git开展一个项目(没有队友,只有我)。 我一直在做提交,合并并将它们推送到远程(所有的混乱,希望我以后学习如何重新定义并修复历史)现在我想重新定义已经在远程的所有更改(仅1个主分支仅1用户),通过rebase我的意思是我要压缩并重命名一些提交。

我正在使用他们在此链接中建议的命令... How to squash commits in git after they have been pushed?,但问题是我遇到了一些错误而且我不理解它们,以下是显示问题的屏幕截图:

image - git cmd rebasing error

image - part of visual history tree

===========================错误作为文本================= ===============

使用的命令:

git rebase -i origin/master~2 master

(它应该只显示2个提交但由于某种原因它显示超过2个,如40 +)

错误讯息:

interactive rebase in progress; onto 9bdd944
Last commands done (15 commands done):
   pick 7af3656 "commit message"
   pick 7355eff "another commit message"
Next commands to do (110 remaining commands):
   pick fc10330 "another commit message"
   pick f22d8c0 "another commit message"
You are currently rebasing branch 'master' on '9bdd944'.

nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyways, use:

   git commit --allow-empty

Otherwise, please use 'git reset'
Could not apply 7355eff... "another commit message"

===========================错误作为文本================= ===============

它看起来像一团糟,任何帮助我解决这个问题的提示都会受到赞赏,我是新用的git,我打赌这对于一些高级用户来说很容易。

1 个答案:

答案 0 :(得分:4)

您可以轻松执行此操作的另一种方法是发出:

git reset -soft d0b8a84d
git commit -m "squashed everything after d0b8a84d"
git push -f

这将首先将历史记录重置回上述提交以及所有基本上“撤消”的更改,但它们仍然存储在暂存区域中。

然后,您可以使用新提交一次性提交所有这些更改。

然后你将它们推回遥控器。它需要一支部队,因为你正在重写已发布的历史。

Git rebase也可以完成,但如果您只想将所有提交压缩到单个提交后的某个点,则上述操作会更容易。如果合并,rebase将提取所有提交,这可能会使事情变得困难。

如果要组合特定提交或更改旧提交等的提交消息,交互式rebase会更强大。但在您的情况下,上述方法更容易。