Git prevents pushing after amending a commit

依然范特西╮ 提交于 2019-11-29 21:18:54

This should only be the case if you're amending an already-pushed commit. Generally you should never do that as you're then modifying published history. In your case however, you should be able to get away with push -f, which will overwrite the remote commit with your amended revision.

Yup, you should not do that (pushing a commit, then changing it and trying to push it again).

Instead, you can roll back Git to your previous commit without changing the files, then creating a new commit:

git reset --mixed origin/master
git add .
git commit -m "This is a new commit for what I originally planned to be an amendmend"
git push origin master

this will create a new commit with the changes you were about to amend.

you amended the pulled commit as in

git pull origin master
git commit -a --amend -m "..."
git push

you can solve the issue by reverting the amended commit:

git reset --mixed origin/master

and then making it again as a full fledged commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!