Search code examples
bashgitdiffcommit

How to diff before each commit without going into interactive mode?


Say you do git status and you get back a list of files which you want to check one by one and then commit them one by one.

Or you do a git diff on a directory and want to go and commit directly after your inspection. How to do that with a simple trick?


Solution

  • UPDATE 2020:

    After fiddling around I decided to install and use ydiff.

    Doing ydiff -s shows a diff side by side in the terminal.

    No brainer check it out here and don't mind my old answer:

    https://github.com/ymattw/ydiff


    [ OLD ]

    Git diff before your commit?

    Simple solution thinking outside of the box:

    Stick this in your .bashrc or .zshrc:

    gdiffy() { git diff $1 && git add $1 && git commit $1; }

    First it will pop open up a diff, when you close it, it will allow you enter a commit message.

    usage example:

    gdiffy config/database.yml

    or

    gdiffy .