MartinM
MartinM

Reputation: 509

Introduce local changes in git to specific comment in the past

Suppose I have 2 commits on top my master branch and some uncommited local changes.
master -> commit 1 -> commit 2 -> (uncommited changes)
In commit 1 I changed just file A, in commit 2 I changed just file B. Uncomitted changes contain both file A and B modifications.
I want to take all uncommited changes to file A and edit commit 1 to contain these changes. Same with commit 2 and file B. I have not pushed yet.
I tried to use git rebase -i with git stash but no success

Upvotes: 0

Views: 23

Answers (1)

Ben
Ben

Reputation: 9703

Here's how I would do it:

$ git add -p

[interactively add your A changes]

$ git commit -m A
$ git add -p

[interactively add your B changes]

$ git commit -m B

Now you have four commits, each changing one file at a time. Now do

$ git rebase -i master

And reorder your commits to be commit 1, A, commit 2, B and mark A and B as fixup. Save and quit and it should rebase cleanly giving what you want.

Upvotes: 1

Related Questions