Hope you're doing well. Thank you for checking out this issue of mine.
I'd like to git diff two commits of two different branches like the following:
git diff temp-branch/working_directory..main/specific_commit
Testing git repo example:
git init
# first write
echo "this is a line" >> file1.txt
git add file1.txt && git commit -m "write a line to file1"
# second write
echo "this is the second line" >> file1.txt
git add file1.txt && git commit -m "write second line to file1"
# third write
echo "this is the third line" >> file1.txt
git add file1.txt && git commit -m "write third line to file1"
# fourth write
echo "this is the fourth line" >> file1.txt
git add file1.txt && git commit -m "write fourth line to file1"
main
's git log
:
commit d68dfcb1537154d0d2c0de1ab6f432032a642fd4 (HEAD -> main)
write fourth line to file1
commit f2538275051c139db38afda1b05d24b3128ef601
write third line to file1
commit 09d3644bf509b58251123033d565564b0a30bcfa
write second line to file1
commit 3801f8850f9480a2ac9644ba65705386d9319e61
write a line to file1
Now I'll do the following: creating a branch with a specific commit ("write second line to file1"), such that the HEAD
is 09d3644bf509b58251123033d565564b0a30bcfa
:
git checkout -b temp-branch 09d3644bf509b58251123033d565564b0a30bcfa
Then I'll write the fifth line to file1.txt:
echo "this is the fifth line" >> file1.txt
temp-branch
's git status
:
Changes not staged for commit:
modified: file1.txt
temp-branch
's git log
:
commit 09d3644bf509b58251123033d565564b0a30bcfa (HEAD -> temp-branch)
write second line to file1
commit 3801f8850f9480a2ac9644ba65705386d9319e61
write a line to file1
Given the current checkout branch is temp-branch
. How do I compare temp-branch
working directory with main
's specific commit that's not HEAD (e.g., f2538275051c139db38afda1b05d24b3128ef601
)? I'd like to compare temp-branch
's "this is the fifth line" with main
's "this is the third line".
In other words, I'd like to git diff temp-branch
's working directory with main
's f2538275051c139db38afda1b05d24b3128ef601
.
Any input is much appreciated. Thank you.