Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move changes to a different commit when interactive rebasing

Tags:

git

git-rebase

While cleaning up (i.e. mostly squashing) the history of some bigger feature, I often end up with the following situation:

Commit A:
  - change A.1
  - change A.2
  - change A.3

// EDIT: maybe some more commits

Commit B:
  - change B.1
  - change B.2
  - change B.3

Suppose that now I want to move change B.1 to commit A using an interactive rebase. The only way I have found so far to do this, is:

  1. Start rebase -i
  2. Edit commit B
  3. Split commit B in tmp commit and commit B (reset HEAD^ and then add -p)
  4. Start rebase -i
  5. Fixup tmp commit in commit A

This requires two rebases and is pretty cumbersome. Also I have to rewrite the commit message of commit B when splitting.

Is there any better/more efficient way to achieve this?

like image 985
gzm0 Avatar asked Nov 01 '22 08:11

gzm0


1 Answers

Probably not a significant improvement, but

  1. git rebase -i A^
  2. git cherry-pick --no-commit B
  3. git add -p
  4. git commit --amend
  5. git reset --hard
  6. git rebase --continue

would be another option.

like image 135
Magnus Bäck Avatar answered Nov 08 '22 07:11

Magnus Bäck