git add -p
will let you add changes to parts of a file
git commit -a
will commit all changes to all files known to git
I want to change what I did in the previous commit. Make everything look like you want it to look. Add the changes and commit with:
git commit --amend
this will change the last commit you did.
You could also move HEAD one back:
git reset --soft HEAD~1
This will let you make your changes, add them and commit them as well. Probably easier if you want to remove a file :)
I added a file, but I don't want to commit it:
git reset <path>
In git you can rewrite history!
git rebase -i HEAD~2
will allow you to rewrite the history of the two last commits. This include removing the commits, rewrite commit messages and squash them.
git reflog
will show all changes
You can undo what you did with:
git revert <commit>
If you want to undo a merge:
git revert -m1 <commit>
Remember: If you revert a change and you want your change back, you must revert the revert :) You can look back, but you must go forward :)