简体   繁体   English

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

[英]Can't squash commits in git after they have been pushed - Visual studio

I'm working on a project (no teammates, only me) using git. 我正在使用git开展一个项目(没有队友,只有我)。 I have been doing commits, merging and pushing them to remote (all disordered with the hope that i learn how to rebase later and fix the history) now I want to rebase all the changes that are already in remote (only 1 master branch only 1 user), by rebase I mean that I want to squash and rename some commits. 我一直在做提交,合并并将它们推送到远程(所有的混乱,希望我以后学习如何重新定义并修复历史)现在我想重新定义已经在远程的所有更改(仅1个主分支仅1用户),通过rebase我的意思是我要压缩并重命名一些提交。

I was using the commands they suggest in this link... How to squash commits in git after they have been pushed? 我正在使用他们在这个链接中建议的命令... 如何在推送后压缩git中的提交? , but the problem is that I get some errors and I dont understand them, here are the screenshots showing the problem: ,但问题是我得到一些错误,我不理解它们,这里是显示问题的屏幕截图:

image  -  git cmd变基错误

图像 - 视觉历史树的一部分

===========================ERROR AS TEXT================================ ===========================作为文本的错误==================== ============

command used: 使用的命令:

git rebase -i origin/master~2 master

(it should show only 2 commits but for some reason it shows more than 2, like 40+) (它应该只显示2个提交但由于某种原因它显示超过2个,如40+)

Error message: 错误信息:

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"

===========================ERROR AS TEXT================================ ===========================作为文本的错误==================== ============

It looks like a mess, any tip that help me to solve this problem would be appreciated, I am new using git and i bet this will be easy for some advance user. 它看起来像一团糟,任何提示,帮助我解决这个问题将不胜感激,我是新的使用git,我打赌这对一些高级用户来说很容易。

Another way you can easily do this is to issue: 您可以轻松执行此操作的另一种方法是:

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

This will first reset the history back to the mentioned commit and all changes that are essentially "undone", but they're still stored on the staging area. 这将首先将历史记录重置回上述提交以及所有基本上“撤消”的更改,但它们仍然存储在暂存区域中。

You then commit all of these changes at once with a new commit. 然后,您可以使用新提交一次性提交所有这些更改。

And then you push these back to your remote. 然后你将它们推回你的遥控器。 It will require a force, since you're rewriting already published history. 这将需要一支部队,因为你正在重写已发布的历史记录。


Git rebase can also be done, but the above is much easier if all you want to do is compress all your commits after a certain point into a single commit. Git rebase也可以完成,但如果您想要做的就是将某个点之后的所有提交压缩到单个提交中,则上述操作会更容易。 The rebase will pull in all commits in case of a merge, which may make stuff hard. 如果合并,rebase将提取所有提交,这可能会使事情变得困难。

Interactive rebase is more powerful if you want to combine specific commits or change the commit message of an old commit etc. But in your case, the above method is soooo much easier. 如果您想要组合特定提交或更改旧提交的提交消息等,则交互式rebase功能更强大。但在您的情况下,上述方法更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM