GIT cheatsheet
Useful commands for your everyday life.
Cancel the last commit and keep the modifications
git reset --soft HEAD@{1}
Add files to an already existing commit
git commit --amend
Vous avez deux commits déjà créés, vous souhaitez les fusionner pour n'en laisser qu'un :
Combine 2 commits
git rebase -i HEAD~2 # "pick" the first commit and "fixup" the second one to make it disappear
Automatically add new files with GIT
git ls-files -o | git update-index --add --stdin git commit -a
In the following parts, SHAx represents the ID of the commit x.
Cancel a commit in the middle of others
git rebase --onto SHA1~1 SHA2
See commits related to a file
git log -- filename
See changed files between 2 branches
git diff --stat --color branch_1..branch_2
See changed files between 2 commits
git diff --name-only SHA1 SHA2 # The same result with details on the change git diff --name-status SHA1 SHA2
See all changes since the last commit
git diff -- # or git diff -- filename
Copy a file from a branch to another
# Copy a file of branch_1 to branch_2 git checkout branch_2 git checkout branch_1 -- filename
Find who to blame for a crappy code
git blame filename
Subscribe and pull a remote branch
git checkout -b branch_x repository_x/branch_x