git - If after committing, you find that something is not perfect and you want to improve it before committing again, how can you cancel the previous commit?
phpcn_u1582
phpcn_u1582 2017-05-02 09:25:39
0
3
648

Or, you can commit later and merge with the previous one.

phpcn_u1582
phpcn_u1582

reply all(3)
左手右手慢动作

If you want to change commit message ,用 git commit -amend.

If you want to add some content, don’t touch the last commit(就叫 commit-1 吧),接着修改,然后提交一个新的 commit (commit-2)。然后 git rebase -i HEAD~~, the following content will appear:

pick commit-1-hash commit-1-message
pick commit-2-hash commit-2-message

Save the second pick 改成 squash and exit, and the following will appear:

# first commit message:
commit-1-message

# second commit message:
commit-2-message

Delete these things and change them to what you want commit messageSave and exit.

Then you can git log 查看一下,两个 commit 已经合并成为新的 commit.

You can refer to:
5. Use rebase -i to merge and submit

===

BTW, if you can only commit the last time commit 已经推到远程分支了,而且该分支有人跟你合作,那么最好还是不要修改了。因为你修改之后,就跟远程分支不同步了,所以需要 git push -f origin your-local-branch, this may cause other people's branches to be out of sync with the remote.

左手右手慢动作

git commit —amend

滿天的星座

Can be used to undo the last submission

git reset HEAD^
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template