3

Suppose I have two branches master and feature, and I'm currently on feature. I don't need to merge these branches, but I want to know amount of conflicts which can give the possible merge. More accurately I want git diff to show only those lines (or only their amount if I'll give --stat option), which will give conflicts if I'll decide to make a merge. I know about --diff-filter=U option which gives me following workaround:

git merge master --no-ff --no-commit
git diff --diff-filter=U -U0     #|grep "@@@"  #if i want only number of conflicted lines
git merge --abort

But this solution has some disadvantages:

  1. It can't be applied if there are uncommitted changes on feature
  2. It's too long and to alias it I need to write much longer script, which will treat different situations like uncommitted changes (using stash) or wrong name for branch to compare (exiting script) or that I'm already in merging state before running the script, etc.

It there a more elegant solution than long aliased script which fakes merging (it is the root of the problems above)?

Dmitry
  • 111
  • 1
  • 10
  • I don't think it can be done without invoking merge, or something equivalent (e.g., `git merge-file` for each file). If there are uncommitted changes, commit them first, on an anonymous branch; then do the merge itself, on the same anonymous branch; then reset back to the commit you just made (use `--allow-empty` to make one even if there are no uncommitted files) and then do a soft reset back to the original branch/commit. – torek Feb 28 '17 at 10:13
  • A similar question was asked [here](https://stackoverflow.com/questions/501407/is-there-a-git-merge-dry-run-option). – kowsky Feb 28 '17 at 10:56

0 Answers0