Can't squash commits in git after they have been pushed
I'm working on a project (no teammates, only me) using 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.
I was using the commands they suggest in this link... How to squash commits in git after they have been pushed? , but the problem is that I get some errors and I dont understand them, here are the screenshots showing the problem:
===========================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+)
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.
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. The rebase will pull in all commits in case of a merge, which may make stuff hard.
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.
链接地址: http://www.djcxy.com/p/49046.html上一篇: 如何挤压和重新绑定已将分支推入主?
下一篇: 在推入后,不能在git中压缩提交