roschach
roschach

Reputation: 9366

Git: how take modifications introduced by a bunch of commits into the branch without committing?

I have a range of commits of another whose modifications I would like to import in my current branch without creating the commit.

I have seen that the cherry-pick command has the option -n to avoid commits. However, when conflicts arise, I do not know how to solve them since with cherry-pick normally one does git add and then git commit -c <hash>.

Is there a way to import the modifications introduced by these commits into the current branch without committing?

I was thinking about creating a patch somehow but I do not know if that's even possible.

Upvotes: 0

Views: 58

Answers (1)

Romain Valeri
Romain Valeri

Reputation: 22017

The git cherry-pick -n route sounds like a good plan.

When conflicts arise, solve them and add your resolutions, then git cherry-pick --continue instead of committing.

You'll end up with a modified index resulting from the cherry-picks and resolutions. At this point you'll be able to inspect/modify/commit as needed.

That being said, even if you had committed the cherry-picks, you still could achieve the same final state with a git reset --soft <hash> afterwards, where <hash> is the pre-cherry-picks position of the branch.

Upvotes: 3

Related Questions