Here I'm going to list some git commands you should know, explain what they do, and use cases
- git diff
- git checkout
- git reset
- git stash
- git commit --amend
git diff
git diff
shows changes between commits, files, commit, etc.
- See what changes have you done since the last commit
you can use git diff
(these changes have to be untracked)
- See changes between 2 commits
git diff <commit id> <commit id>
recommend you to put the commitid's in this order: <older commit> <newer commit>
Use cases
- See what has changed between 2 commits
- compare what changes you have done since the last commit
git checkout
git checkout
allows you to move through the history of your repository, read, write, and come back, also you can use it to change between branches
- go to a specific commit
git checkout <commit id>
to come back you just need to write git checkout <actual branch>
, if you are in the development branch, you use git checkout development
and you are on the HEAD of your branch
Use cases
- see the state of your project in a specific commit
git reset
git reset
allows you to move through the history of your repository, like git checkout but you can't come back
- go to a specific commit hard
git reset --hard <commit id>
this is going to change your HEAD position to your commit id, removing all commits above that.
you can use it on your computer and see that the commits above are no longer.
Use cases
- delete changes that you did that have a bug quickly
git stash
git stash
, stash the changes in a dirty working directory away, you can use it when you want to remove changes haven't you commit or just see how the directory was without that changes
- see how the directory was without that changes
git stash
to save you changes in a temporary space and to bring them back use git stash pop
- remove changes haven't you commit
git stash
and then git stash drop
Use cases
- delete changes have you done since the last commit
git commit --amend
git commit --amend
allows you to add changes to the last commit without making another one and change the commit message.
git add .
to add your changes to staging and the git commit --amend
after this, you'll be able to change your commit message, after that, there is no new commit and your changes are committed
Use cases
- You were wrong writing the commit message and want to change it
- you forgot made little changes that belong to the last commit
I recommend you to prove these commands on your own computer to get more familiar with them, I hope you learned something :).
Tell us if you know another git command that could be useful and everyone should know.
Top comments (0)