0

I've got a challenge regarding GIT. I'm trying add and checkout specific files when a merge fails. I already created a post-merge hook which checks if there are files with UU-flag (Both modified) but the post-merge hook isn't invoked when a merge fails.

### Are any Sass files canged and added?
if git status -s | grep  '^UU.\+styles\.css$'
then
    git add skin/frontend/responsive/*/styles.css -f
    git checkout --theirs skin/frontend/responsive/*/styles.css
    git commit -m 'Added and checked out specific css-files from the     incoming branch to avoid merging binary files'
else
    echo "didnt find conflicted files"
fi
exit 0

I've thoroughly searched for a solution or something but couldn't find a way to automatically check for merge conflicts after a merge fails. The only thing that came close enough was a python-script which fired when a pre-commit is invoked. So, is there a hook which I can use when a merge fails?

Thanks in advance

  • This is in general not a good idea (e.g., watch out for ours/theirs role reversal during rebase). However, your add and checkout commands are in the wrong order here, if you just want to take their version of these styles.css files—you need to extract stage 3 (theirs) to the work-tree first, and *then* use `git add`, preferably without `-f`, to tell Git to replace the three conflicted copies with the work-tree copy at stage 0. – torek Mar 20 '18 at 15:20
  • Thank Torek. I changed the order of the add and checkout commands. But you think a automatic script after a failed merge isn't good idea? – Tachyon Mar 22 '18 at 10:16
  • If you're doing very controlled operations, you could run `git merge`, and then run your own script commands, but just having it run after *every* failed merge means you'll run it after some cherry-picks and reverts as well. If you build your own script that first runs `git merge`, you can easily tell if the merge failed: it prints messages and returns a nonzero exit status. – torek Mar 22 '18 at 15:12

0 Answers0