Skip to content

black-desk/git-sort

Repository files navigation

git-sort

checks commit activity contributors release date commits since release codecov

en | zh_CN

Warning

This English README is translated from the Chinese version using LLM and may contain errors.

A git extension command that sorts commits by their topological order on a reference branch. Useful for backport workflows where commits need to be applied in the correct dependency order.

Usage

git-sort [OPTIONS] [INPUT]

ARGS:
    <INPUT>    Input file containing commit hashes (one per line).
               Use '-' for stdin. [default: -]

OPTIONS:
    -o, --output <FILE>    Output file. Use '-' for stdout. [default: -]
        --reference <REF>  Reference branch for topological ordering [default: HEAD]
    -h, --help             Print help
    -V, --version          Print version

Input Format

Each line contains a full commit hash, optionally followed by a tab and the commit title:

<full-commit-hash>\t<optional-title>

The output preserves the input format, only changing the order.

Examples

# Sort commits from a file
git-sort commits.txt

# Sort commits from stdin
git log --format='%H\t%s' main..feature | git-sort

# Use a specific reference branch
git-sort --reference main commits.txt -o sorted.txt

# Can also be invoked as a git subcommand if in PATH
git sort commits.txt

Performance

For large repositories, it is recommended to generate a commit-graph first for better performance:

git commit-graph write

If no commit-graph is found, git-sort will print a warning.

License

Unless otherwise specified, the code of this project are open source under the GNU General Public License version 3 or any later version, while documentation, configuration files, and scripts used in the development and maintenance process are open source under the MIT License.

This project complies with the REUSE specification.

You can use reuse-tool to generate the SPDX list for this project:

reuse spdx

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Generated from black-desk/template