jesseduffield / jesseduffield/lazygit

Easily convert changes to a single commit

Open
#2,249 7 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
82.4k
Forks
3k
Avg merge
2d 18h
Merged PRs (30d)
19

Description

**Is your feature request related to a problem? Please describe.**
Often I come across a PR which has maybe 3 or 4 commits but has a bunch of merge commits merging master into the branch. So it's a bit of a mess and it would be much better if it was just a single commit (because the PR isn't actually doing much).

I know github has a feature where you can squash before merge, and that's basically what I want here, except I only want the squashing part, because there may be more commits to come on the PR and it may make sense logically to have those remain as separate commits.

**Describe the solution you'd like**
Upon pressing a certain key, the following happens:
* we stash any working tree changes
* we obtain the diff between the current branch and the most recent common ancestor of the master branch. This is what we want in the commit we're going to create
* we write that diff to a patch
* we hard reset the current branch onto the common ancestor commit
* we apply the patch and commit it
* we apply the stashed changes

**Describe alternatives you've considered**
This could just be a custom command, and I want to start it off as just a custom command, but I'd like this to live inside lazygit because it's such a common thing I come across and it's typically on other people's PRs where the person isn't very well versed with git (so it's easy to say 'download lazygit and press this key')

**Additional context**
Here's what the command could look like:
```
MERGE_BASE=$(git merge-base {{.Branch}} HEAD)
git diff --binary {{.Branch}}...HEAD > /tmp/mypatch
git stash save "Lazygit: Stash before applying patch"
git reset --hard "$MERGE_BASE"
git apply --index /tmp/mypatch
git commit -m {{.CommitMessage}}
git stash apply stash@{0}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.