This cheatsheet is a GIT 101 on the basic commands that are used on a day to day basis. At the time of writing I was using git version 2.27.0.windows.1.
Note: certain actions can be accomplished in more than one way however; I have chosen to show just one way. E.G GIT CHECKOUT <FILE> and GIT RESTORE <FILE> do the same thing.
- Understanding the Four Different Areas
- Making Changes and Committing Them
- Reverting Changes Back to Previous State
- Comparing Changes between the Areas (DIFF)
Understanding the Four Different Areas
The key to really understanding GIT is understanding these four areas. Changes flow from left to right and undoing changes flow from right to left.
Unfortunately there is some inconsistency when referenced in documentation or across the internet. For example; the Staging area is also known as the Cache or the Index. You see this is some of this in the command syntax.
Making Changes and Committing Them
These are typically your bread and butter commands for every day changes.
Reverting Changes Back to Previous State
inevitably there will always be occasions when you need to rollback changes to files.
You may have made changes to files in your working tree which are un-staged and need to be reverted back to the last commit.
If you have made some changes and staged those changes, you can just un-stage them which leaves them in your working tree. You can then either re-stage them or revert the files back to the previous commit.
We may have committed changes to a file and then want to revert those file change back to a previous commit.
Comparing Changes between the Areas
Sometimes we would like to do a DIFF between the areas for a specific file.