Checking (git) changes from terminal

codes
git
version control
comparision
2022

What changes did I make?

Author

Pratik Bhandari

Published

April 18, 2022


One of the main reasons for using git is version control. No longer naming the files as ‘final-draft’, ‘finaly-draft2’, ‘final-finaldraft_pb’, etc. You can see what changes have been made incrementally: Compare the version of the document created 10 days ago with the recent one.

Example:

Say we have a file 01_chapter.Rmd. It is the first chapter of my thesis. I have just made some changes to it. Before git add <file>, I want to compare these changes with the latest version I have already committed. Then, this is what I do1:

Code
git diff HEAD 01_chapter.Rmd
# OR
git diff master:01_chapter.Rmd 01_chapter.Rmd

If 01_chapter.Rmd is not in the working directory, then provide the path to it.

Other different comparisons:

Code
git diff HEAD~2 01_chapter.Rmd
# OR
git diff master~2:01_chapter.Rmd 01_chapter.Rmd
#--

git diff master~3:01_chapter.Rmd master~1:01_chapter.Rmd

You got the idea.

The global comparison of all files is just git diff which I do not prefer.

Tip: If you are working on RStudio, its GUI shows the changes in files since the last commit, including what files are added or deleted.

Footnotes

  1. More in here↩︎