Skip to content

SpicyLemon/git-diff-explorer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn

git-diff-explorer

A CLI git diff explorer written in bash that utilizes fzf.

Table of Contents

  1. About The Project
  2. Prerequisites
  3. Installation
  4. Usage
    1. Examples
  5. Contributing
  6. License
  7. Contact

About The Project

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.

git_diff_explorer example screenshot

Prerequisites

You must have the following utilities available:

  1. git - Git is a free and open source distributed version control system.
  2. fzf - fzf is a general-purpose command-line fuzzy finder.

See each project for installation instructions.

Installation

  1. Download git_diff_explorer.sh.
  2. Do one of the following:
    • Copy it to a directory in your PATH.
    • Update your enviroment initialization scripts (e.g. .bash_profile or .zshrc) to source the file.

Usage

This command:

> git_diff_explorer tag-v0.45.4..tag-v0.46.0

lead to this screenshot: git_diff_explorer example 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 is combined.
  • --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 to xargs -0.

All other arguments are provided to the git diff commands.

There is also --help available.

Examples

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:]]+'

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

If you export DEBUG=1, some debug information will be printed when you run git_diff_explorer.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Daniel Wedul - @dannywedul - [email protected]

Project Link: https://github.com/SpicyLemon/git-diff-explorer

About

A git diff explorer written in bash utilizing fzf

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages