arxoft
arxoft

Reputation: 1475

git merge but keep incoming changes unstaged

Say my current branch is feature-foo and the working directory is clear (there are no modified files). And I merge another branch feature-baz on it by: git merge feature-baz.

What I want is that all the changes from the branch feature-baz are applied to the files on my current branch but the merge commit should not happen. So, when I do git status, I should see all the modified files still unstaged.

Is this possible in Git? If yes, how...?

I want to do this because this way, I would be able to do the changes into the code during my code-review process. And then do a manual commit instead of an automated merge commit which is done by Git.

Thanks

Upvotes: 5

Views: 1737

Answers (2)

chepner
chepner

Reputation: 532418

Use the --no-commit and --no-ff options with git merge:

$ git merge --no-commit --no-ff feature-baz

--no-ff ensures that the merge would create a commit, even if a fast-forward is possible. --no-commit updates your working directory, but stops before creating the merge commit.

Upvotes: 5

Michał Turczyn
Michał Turczyn

Reputation: 37500

Just use git reset HEAD^ after merging with git merge.

Important thing is that you merge (this will create merge commit, as you know) and then use git reset HEAD^ - HEAD^ will cause to "revert" to commit before last commit on current branch (!), so right before merge commit.

All changes from that commit will be:

  • moved to index (shown as added) if you use git reset --soft HEAD^
  • completely unstaged (shown as unstaged) if you use git reset --medium HEAD^
  • if you use git reset --hard HEAD^ changes will be removed completely, from GIT and from disk, so you do not want that.

Side note: --medium is default option, so you can omit it.

So you want to do:

git merge feature-baz
git reset HEAD^

Upvotes: 0

Related Questions