2

How do I definitively stop Git from trying to merge? I never want it to merge.

From How to make Git honor a cancelled merge that was not asked for?, I know the tool does not respect my cancellation by killing the editor it spins up without asking me. So now I just kill -9 the terminal process.

If I get into a situation where Git wants to merge, I always want the server's copy of the source file. I'll just delete the file locally and then fetch it again from the server.


Right now, Git is DoS'ing me with this piece of goodness:

You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.

Of course, the git reset HEAD <file> did not work.

And here's the best part: they are the exact same file. There are no differences between them. I make a change, I test it on 8 to 12 different platforms (copying with scp), and then I check it in on one of those boxes after testing. But from Tell Git to stop prompting me for conflicts when none really exist?, I know the tool is too stupid to show any intelligence in this area.


If you are wondering, there is one set of sources. They are the project's sources located on the remote server. All I want Git to do is checkout (clone), update (pull), tell me what has changed (diff) and checkin (push). I don't need any other features from the tool.

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885

2 Answers2

4

You could declare a custom merge driver for '*' (all files) in a .gitattributes, with a keepTheir script.

echo * merge=keepTheir > dirWithCopyMerge\.gitattributes
git config merge.keepTheir.name "always keep theirduring merge"
git config merge.keepTheir.driver "keepTheir.sh %O %A %B"

keepTheir.sh would be:

mv -f $3 $2
exit 0

I need to get the server's copy of a file (and possibly meld changes). Under Subversion, I would use svn update

Easy: use git fetch (which won't trigger any merge), and then git checkout:

git checkout origin/master -- path/to/file

(See "git: how to update (checkout) a single file from remote origin master")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @jww normally, a `git merge --abort` is enough to stop the merge. – VonC Jul 21 '15 at 10:53
  • 1
    It starts the process automatically when I do a `git pull`. I never do a `git merge`. I have ***never*** issued the command. – jww Jul 21 '15 at 10:59
  • 1
    @jww git pull is git fetch + git merge, so that makes sense. – VonC Jul 21 '15 at 11:00
  • Thanks VonC. So maybe I should back up then. I need to get the server's copy of a file (and possibly meld changes). Under Subversion, I would use `svn update`. When I researched it in the past, I was told to use `git pull`. But it appears `git pull` may be the wrong tool for the job. What should I be using get the server's copy of a file (and possibly meld changes)? – jww Jul 21 '15 at 11:45
  • @jww I have updated my answer, in order to not use git pull. – VonC Jul 21 '15 at 11:49
0

Add this to your .git/config

[merge "keepTheir"]
   name = always keep their during merge
   driver = cp -f %B %A 

and add this into your .gitattributes

public/dist/app.min.css merge=keepTheir
Jad Joubran
  • 2,511
  • 3
  • 31
  • 57