A CLI git diff explorer written in bash that utilizes fzf.
There is a single file: git_diff_explorer.sh. It can be executed directly or it can be sourced to add the git_diff_explorer
function to your environment.
The git_diff_explorer
takes in any arguments you'd provide to a git diff
command. It runs the git diff
command using --compact-summary
and displays the output in fzf
in a bottom, selection area. The diff of the highlighed file is shown in an upper, larger area. If lines are selected, their filenames are printed upon exit.
You must have the following utilities available:
- git - Git is a free and open source distributed version control system.
- fzf - fzf is a general-purpose command-line fuzzy finder.
See each project for installation instructions.
- Download git_diff_explorer.sh.
- Do one of the following:
- Copy it to a directory in your
PATH
. - Update your enviroment initialization scripts (e.g.
.bash_profile
or.zshrc
) tosource
the file.
- Copy it to a directory in your
This command:
> git_diff_explorer tag-v0.45.4..tag-v0.46.0
lead to this screenshot: And this output:
codec/legacy/codec.go
codec/proto_codec.go
codec/legacy/doc.go
A --commit <hash>
option is also available to get the diff of a single commit. It is transformed into the arguments <hash>~
<hash>
.
Output can be controlled with a few custom options too:
--output-type <output type>
- This only affects moved files.<output type>
can be one of the following:old
- only the old filename (of selected lines) is printed.new
- only the new filename (of selected lines) is printed.combined
- output the combined old => new entry (from the compact summary) of selected lines.both
- output the old file on one line, then the new file on another (of selected lines). The default iscombined
.
--printd <delimiter>
- Use the provided delimiter between each selection's output. The default is\n
.--print0
- Use a null byte as the delimiter. This is the same as--printd \0
. This is handy when there are spaces in the name and you are piping the output toxargs -0
.
All other arguments are provided to the git diff
commands.
There is also --help
available.
Explore the differences between main and your current branch:
> git_diff_explorer main
Explore the differences between two branches:
> git_diff_explorer branch1 branch2
Explore your unstaged changes and stage the files you select:
> git_diff_explorer --print0 | xargs -0 git add
Explore the changes from a single commit:
> git_diff_explorer --commit 01ab23cd4
Explore a word diff from a single commit:
> git_diff_explorer --commit 01ab23cd4 --word-diff=color --word-diff-regex=[[:alnum:]]+'
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
If you export DEBUG=1
, some debug information will be printed when you run git_diff_explorer
.
Distributed under the MIT License. See LICENSE for more information.
Daniel Wedul - @dannywedul - [email protected]
Project Link: https://github.com/SpicyLemon/git-diff-explorer