0

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.

roschach
  • 8,390
  • 14
  • 74
  • 124
  • 3
    Although your question is answerable, it's kind of a strange question. Why don't you want to commit? Note [Romain Valeri's answer](https://stackoverflow.com/a/73111193/184546) shows that it doesn't matter if you commit since you can reset immediately afterwards. You could also amend with new changes if that's your ultimate goal. Also, this sentence is sort of strange too: "Is there a way to import the modifications introduced by these commits into the current branch without committing?" If you leave the changes pending or staged, they are **not** part of the current branch yet. – TTT Jul 25 '22 at 16:22

1 Answers1

3

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.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61