Code
git diff HEAD 01_chapter.Rmd# OR
:01_chapter.Rmd 01_chapter.Rmd git diff master
What changes did I make?
Pratik Bhandari
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.
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:
If 01_chapter.Rmd
is not in the working directory, then provide the path to it.
Other different comparisons:
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.