Simple command-line tool for fast comparison between two branches
NB: The same functionality is provided out-of-the-box by git-diff tool
- you performed rebase with commit fixups/reordering/conflict resolutions
and want to make sure new version didn't introduce any unintended code lines or dropped useful ones - you want to see the differences between the current branch (
HEAD
) and other branch (git cmp other_branch
) - you want to see the differences between any two branches (
git cmp branch1 branch2
)
- Suppose you started with the following repository state:
- Now suppose you want to switch order for second and third commits and edit the contents of the first commit.
You do that with the following git command:git rebase -i HEAD~3
The repository reflects the changes:
- To see all the differences between
master
andmasterBackup
branches
you can execute the following git command:git cmp master masterBackup
(or shorter:git cmp masterBackup
)
Now there's two possible outputs:
a) You didn't introduce any changes:
b) You did introduce some changes (which may be intended or not):
- Now you know exactly what changed after rebase.
It's up to you to decide what to do next (deletemasterBackup
branch or discard rebase, for example)
Installed git
- Download and save cmp.sh in a folder of your preference (for example:
"C:/scripts"
) - Add alias to global
.gitconfig
file (default path:"C:/users/%username%/.gitconfig"
):
git config --global alias.cmp '!sh C:/scripts/cmp.sh'
- Check whether it works by typing in bash shell:
git cmp
The output should look something like this:
$ git cmp
Illegal number of arguments (1-2 expected, 0 provided)
usage: C:/scripts/cmp.sh [local_committish] remote_committish
local_committish current tree state. HEAD by default
remote_committish previous tree state
note: "committish" is a commit hash/branch name/tag
- You are awesome! From now on you have a tool relieving you from anxiety after any non-trivial rebase
Windows & Unix
- Andronov Alexey - Idea & Implementation - git-cmp