Today I learned how to diff between two branches.
git diff feature..main
Sometimes we get a little
git add . && git commit -m "WIP"
happy and mistakenly commit something that we just can't figure out. This is a good way to figure out what the heck has changed on the current branch compared to any other branch.
Let's create a new directory, initialize git and toss some content into a readme.
mkdir git-diff git init echo "hello there" > readme.md git add . && git commit -m "hello there" cat readme.md
After all of that, we have a git repository on our local machine with a single file
that contains the following.
Let's checkout a new branch called Waylon and change the word
file, then diff it.
git checkout -b Waylon echo "hello Waylon" > readme.md git add . && git commit -m "hello Waylon" git diff
- hello there + hello waylon
At this point we have one commit. Things are really straightforward, and our diff will be the same between the last commit and the main branch since. Let's make another commit by adding the date.
echo "hello waylon\n\n$(date)" > readme.md cat readme.md git diff
hello Waylon + + Fri 13 Mar 2020 04:23:21 PM DST
git add . && git commit -m "add date" git diff main..waylon
- hello there + hello Waylon + + Fri 13 Mar 2020 03:43:21 PM DST
I learn small tricks like this often with git. Many times I forget about it and have to come back to re-learn. Sharing my thoughts gives me a better chance of remembering.