0 votes
1 view
in Devops and Agile by (20k points)
edited by

Is it possible to do a git merge, but without a commit?

"man git merge" says this:

With --no-commit perform the merge but pretend the merge failed and do not autocommit,

to give the user a chance to inspect and further tweak the merge result before

committing.

But when I try to use git merge with the --no-commit it still auto-commits. Here's what I did:

$> ~/git/testrepo$ git checkout master

Switched to branch 'master'

$> ~/git/testrepo$ git branch

* master

  v1.0

$> ~/git/testrepo$ git merge --no-commit v1.0

Updating c0c9fd2..18fa02c

Fast-forward

 file1 |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)

$> ~/git/testrepo$ git status

# On branch master

# Your branch is ahead of 'origin/master' by 1 commit.

#

nothing to commit (working directory clean)

A subsequent git log reveals all the commits from the v1.0 branch merged into master.

1 Answer

0 votes
by (28.4k points)

As you can notice that the output while performing the merge says Fast Forward

The typical suggestion would be the following:

git merge v1.0 --no-commit --no-ff

But let us talk about --no-commit and what does it represent. '--no-commit' would simply prevent the merge commit to occur and that would only happen when you merge two divergent branch histories. But in your example that's not the case since Git indicates that it was a "fast-forward" merge and then Git only applies the commits already present on the branch sequentially.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...