- Fix typo in last commit message
git commit --amemd -m 'Your new commit message
- Add more changes
# do more changes
git add file1 file2
git commit --amend
- Only change files, no change in commit message
git add file1 file2 ...
git commit --amend --no-edit
- Reset changes done in WORKING AREA, if you have already stagged the changes(
git add
), you need to reset.
git checkout -- file
- Checkout to a specific commit(deattached head).
git checkout SHACommit
NOTE: Do not change anything here, should be useful for debuging purpose, avoid creating new commits here.
- Moving file from staging area to working area.
git reset filename
- Deleting previous commits
A -> B -> C -> D
Suppose there was a bug which was introduced in commit C
. You can move back to commit B
which is most stable version while
- keeping changes done in both commit
C
&D
in working area
git reset --soft B
- deleting every change done in both commit
C
&D
git reset --hard B
Now you can do the required changes and and commit. You may need to push using -f
flag.
- Reverts changes done in a specific commit, this reversion is added as a separate commit on top of current HEAD.
git revert SHA_of_your_commit_you_want_to_revert