Home

Compare two git commits using GIT CLI

Compare two commits in the CLI

The following command lets you see the changes in between two commits. The commits are identified using hashes i.e., sha1 and sha2 are the sha hash of the commits you want to compare.

git diff <sha1> <sha2> | less

You can find the hash of the commit using the git log command. A hash will look like 01a6644b37b95d2213489090e5231778279d209f, but you can just use the first 7 chars to refer it because it is most probably unique e.g.,git diff 01a6644 8c8b00b | less

Copying the results of the comparison to a file

To copy the output of the above command to a file, you can run the following command:

git diff <sha1> <sha2> > diff.txt


Last Updated on

Next Post: GraphProtocol: TS2322 null assignment in Subgraph →

Comments