An open API service indexing awesome lists of open source software.

https://github.com/thomasbachem/git-edit

Easily edit Git commits via interactive rebase
https://github.com/thomasbachem/git-edit

command-line git rebase zsh

Last synced: about 1 month ago
JSON representation

Easily edit Git commits via interactive rebase

Awesome Lists containing this project

README

          

# git edit – Easily edit commits via interactive rebase

This Git subcommand script makes it easy to edit, modify, drop, or merge previous commits. It's essentially a more convenient wrapper around `git rebase --interactive`, with automatic stashing/unstashing and integrated merge conflict handling.

## Usage

```
git-edit [-m | --message]
git-edit [-d | --drop | -s | --squash] ...

MODES:
-e, --edit Edit (default mode)
-d, --drop Delete (drop) one or more s or ranges
-s, --squash Merge (fixup/squash) one or more s into the oldest one
-s , --squash Merge (fixup/squash) s into
– also assumed when multiple commits are supplied
FLAGS:
-m, --message Alter message after applying changes
```
*Tip:* Mode and flags can be given in any order.

## Usage Examples

### Editing

Open the given commit for manual editing, keeping its commit message (or add `-m` to also edit the message):
```
git edit 0123456789abcdef0123456789abcdef01234567
```
This will:
1. Stash any current local changes
2. Reset to the chosen commit
3. **Pause so you can make changes**
4. Amend the commit and continue the rebase (pausing if merge conflicts occur so you can resolve them)
5. Restore your stashed changes

### Merging

Merge multiple commits into the oldest one among them, keeping only the target commit's message (or add `-m` to also edit the message):
```
git edit 0123456789abcdef0123456789abcdef01234567 abcdef0123456789abcdef0123456789abcdef01
```
*Note:* You can also use ranges (e.g., `git edit HEAD~3..HEAD`).

This will:
1. Stash any current local changes
2. Determine the oldest of the provided commits, making it the target
3. **Merge the newer commits into it**
4. Continue the rebase (pausing if merge conflicts occur so you can resolve them)
5. Restore your stashed changes

## Screenshot

![Screenshot](/screenshot.png?raw=true)

## Installation

Make the script available as a Git command by adding its folder to your `PATH`, e.g. by adding this line to `~/.zshrc`:
```
export PATH="$PATH:/your/path/to/git-edit"
```

## ⚠ Warning: History Rewriting

This script rewrites Git history from the chosen commit onward — changing the SHA-1 of that commit and all later commits.
- Safe if: Commits haven’t been pushed yet, or you’re the only developer
- Risky if: Others have based work on these commits (branches, forks, etc.)
If rewriting history, you’ll need to force-push (`git push --force`), which can disrupt collaborators.