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.
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
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.
# 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.txtFor large repositories, it is recommended to generate a commit-graph first for better performance:
git commit-graph writeIf no commit-graph is found, git-sort will print a warning.
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