Git workflow for re-doing the commits of a large MR?

Sometimes there is a need to re-work a large MR and today a co-worker showed with his vim the following workflow.

  • Make a new branch from master
  • Use vimdiff to compare side-by-side the MR branch and the new branch
  • Take some logical sets of changes (I’ll guess they were patches/hunks) with a single key press (that is, he copied some diff lines from MR branch to new branch and made a commit out of that. Side-by-side diff view was nice as it showed immediately that the files/lines were the same after copying and commit. And he could easily change the file which he compared and move forward and backward to the next/prev the hunk etc.
  • After doing those new commits on the new branch, he was able to split the original into nicer set of commits, and especially, into a set of smaller MR’s (which is nice for the reviewers).
  • And at the end, he could show that the diff between branches was nill so that the re-organized commits did the same job.

Picking up commits from the large MR wasn’t ok as there already had happened a lot of re-writing etc. (Commits combined changes of un-related sub-features.)

Is the above workflow possible with kakoune at the moment? (I think some time ago it was said that there is no side-by-side view at kakoune yet. But is this so? In a way fifo buffer using the diff tool giving the side-by-side might could do it somehow. Anyhow, not sure at all.)

And of course it would be interesting to hear if you have some other ways of doing approximately the same thing (of re-organizing a large MR into manageable pieces) with kakoune (or some other terminal tool).

1 Like

I usually do an interactive rebase, reordering, squashing and editing commits as needed but there are some extreme cases where this sort of surgery you describe could be needed. Honestly you don’t need an editor to do it, git has the patchwise interactive commands you can run direct in the terminal. Here’s how I would do it:

git checkout mangled-branch 
git reset --soft master # this moves HEAD to master without touching your working directory
git checkout -b new-branch # this creates a new branch off HEAD, which is master
git commit -p # review changes by patch, accepting or denying, or even editing, then commit. Repeat as many times as needed to obtain sane commit history and there are no changes left
git diff mangled-branch # convince yourself there's nothing different about the branches

You can of course do this in a :repl for side by side in whatever windowing system you’re using.

1 Like

kakmerge might be interesting as well as an alternative to vimdiff.

1 Like

Sorry to answer a question about “how to do in $X” with “use $Y” – but honestly, the more I use Lazygit the more I love it. Rebasing in it is incredible.

1 Like