If, after the commit, it is found that there is still one thing that is not perfect, how can we cancel the previous commit if we want to perfect it and then re-commit?

  git, question

Or, the merger of the subsequent commit and the previous one can also be carried out.

If you want to changecommit messageWithgit commit -amend.

If you want to add some content, don’t move the previous one.commit(just callcommit-1, then modify, and then submit a newcommit(commit-2)。 Thengit rebase -i HEAD~~, the following will appear:

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

Will the secondpickChange tosquashSave to exit, appear:

# first commit message:
 # second commit message:

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

Then you cangit logCheck it out, twocommitHas been merged into a new onecommitHere we go.

You can refer to:
5. submit by rebase -i convergence


BTW, if you lastcommitIt has been pushed to the remote branch, and someone in this branch is cooperating with you, so it is better not to modify it. Because after you modify it, it is out of sync with the remote branch, so you need togit push -f origin your-local-branchTo submit, which may cause other people’s branches to be out of sync with the remote.