Is there any way of simulating a git merge
between two branches, the current working branch and the master, but without making any changes?
I often have
I don't know exactly if it is your case, but your question remember me that sometimes I start a feature, I commit over the days and I merge the develop on it many times.
On this point I lose the control over the exact files I changed and I will only know it when my feature were closed and my code go to develop.
In this case, a good way to know what modifications you did (not other from the merges) is using Sourcetree.
You must click with the right button on the base branch and select Diff Against Current
:
Then sourcetree will show you all the modifications that will be merged if you merge your branch into base branch.
Of course, it will not show you the conflicts, but it is a useful tool in merges.
Why not just create a throwaway branch (git checkout -b), and do a test merge there?
I use :
git merge --ff-only
according to documentation:
Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward.
It's not really a simulation because there will be a fast-forward merge in case of no conflicts between the two branches. But in case of conflicts, you will be informed and nothing will happens.
I don't think there is a way of simulating what will happen until you try the merge. However, if you make sure that the output of git status
is empty before you do the merge, it is quite safe to just go ahead and try it. If you get conflicts, you can immediately get back to the state you were at before with:
git reset --merge
Since git 1.7.4, you can also abort the merge by doing:
git merge --abort
(As the commit message that added that option explains, this was added for consistency with git rebase --abort
and so on.)
I've been able to use git merge --abort
, recently. However, this can only be used if there is a merge conflict. If you are sure that you will not want to commit, then use the other mentioned methods above.
You can use git merge --no-commit
to prevent the merge from actually being committed, and if you don't like how the merge works out, just reset to the original head.
If you definitely don't want to finalize the merge, even if it's a fast-forward (and thus has no conflicts, by definition), you could add --no-ff
as well.