Or, you can commit later and merge with the previous one.
ringa_lee2017-05-02 09:27:39
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 message
Save 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.