I have a file which I have changed to add 2 new features to the systems. Now I only want to commit one of the features on the branch. So I went through the changes with git add -p and now I want to verify that I only got the parts of this one feature and that I didn't forget any. Therefore my idea was to look at the differences as diff between {HEAD, staged, working dir}.
I tried to get the right handles for the different files and then combine it with a git difftool call.
HEAD: git show HEAD:src/autosub.py --> HEAD:src/autosub.py
staged: git show :src/autosub.py --> :src/autosub.py
working dir: src/autosub.py
But the combined call does not work: git difftool HEAD:src/autosub.py :src/autosub.py src/autosub.py
What am I doing wrong? Thx!
git diff:
git diff [options] [<commit>] [--] [<path>...]
It only accepts commit as arguments and is not really intended to do a diff3 with other things than commit.
You have to do it in 2 parts:
git diff[tool] HEAD : git diff[tool] --staged (or git diff --cached)The second one is the way to see what you will commit.
You can configure diff.mnemonicPrefix to see the w (working dir), i (index/stage), or c (commit/HEAD) prefix in the diff instead of a and b.
If you really need to do a diff3 between WD/stage/HEAD:
git show HEAD:path > /tmp/head
git show :path > /tmp/staged
diff3 /tmp/head /tmp/staged path
rm /tmp/head /tmp/staged
You can put this in a shell function or a script then add it as an alias:
# Diff-3 between _C_ommit/_I_ndex/_W_orkingdir
git config --global alias.diff3ciw '! the_script'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With