Answers
What do you do if you left out a changed file in the last commit?
You solve this with the same command you use to modify the message in the last commit, using --amend
, but you need to indicate that you do not want to edit the message (make sure your files are staged):
git --amend --no-edit
What do you do if you committed to the wrong branch?
Checkout or create the branch you want to have committed to and then use reset to remove the change from the remote branch, but leave your files in the index (staging area) to be committed to the new branch:
git branch <new branch>
git reset HEAD~ --hard
What do you do if you corrupted a file in a previous commit?
First, use git log
to find a commit before the corruption. Get the ObjectID of that commit. Next, get the problem file (and only that file) from the good commit:
git checkout ObjectID --<path to file>
Remember: The path to the file is relative to the root of the project.
...