Git commit amend - modify the last commit

This trick is for people that don't double-check what they're doing. If you have pressed the enter key too early, there's a way to modify the last commit message or add that file you forgot, using the git commit command with the --amend option:

$ git commit --amend -m "New commit message"

Please note that with the --amend option, you are actually re-doing the commit, which will have a new hash; if you already pushed the previous commit, changing the last commit is not recommended - rather, it is deplorable.

If you amend an already pushed commit, then push the new one, you are basically discarding the latest commit on a branch, replacing it with the newly amended one: for those who will pull the branch, this can lead to some confusion, as they will see their local branch losing the last commit, replaced by a new one.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.13.255