eriophora
eriophora

Reputation: 1049

Print a list of conflicts that will result from a merge

I'm looking to merge two git repos, and I'm told they cannot be resolved automatically.

I'd like to type a sequence of commands into the terminal and obtain a list of lines from files in either repo that are preventing the merge from taking place automatically.

I'm one hundred percent sure I'm not the first person to have this question (indeed, I imagine every person who has ever tried to merge two git repos has had this question) yet I'm having enormous difficult finding a simple answer (or any answer). Nonetheless, I'm sure the answer exists and is likely simple. Git determines unmergeable conflicts algorithmically, and since we're dealing with text files and not quantum phenomena I can't see why it should be difficult to observe what conflicts will be unmergeable before I actually merge the two.

It's possible that the reason I can't find anything is because no one uses git to do this, and my workflow when merging repos is orthogonal to the way everyone else does--if this is the case please enlighten me!

Thanks!

Upvotes: 1

Views: 259

Answers (1)

Schwern
Schwern

Reputation: 165416

One of the great things about Git is almost everything can be undone.

Do the merge, diff, and then throw out the merge attempt.

  1. git merge -n blah (-n will assure the merge is not committed)
  2. git diff > conflicts.txt
  3. PROFIT!
  4. git reset --hard HEAD

You can do whatever you like in step 2 to investigate the conflict, step 3 will throw it all out.

If somehow the merge happens, you can immediately git reset --hard HEAD@{1} to undo the merge or git reset --hard <id before the merge> later.

Upvotes: 2

Related Questions