5

Good evening!

I know this is very usual and there are probably thousands of answers on the internet but I couldn't find one that was helfull.

I have two local branches:

  • MASTER
  • Mk

I made a lot of changes to Mk, committed these, and switched to MASTER to merge these two branches. But there were conflicts. So now I am on the MASTER branch, can not switch to Mk anymore, but need to override my MASTER with Mk.

It keeps saying

error: Your local changes to the following files would be overwritten by merge

Is there a way to do this?

 git mergetool --tool=meld    #No files need merging
 git merge -s theirs Mk       #Could not find merge strategy 'theirs'.
 git merge -X recursive=theirs Mk   # error: Your local changes to the following files 

would be overwritten by merge

and I did not push my changes to my online repository yet.

I can see the commit with all the changes but can not access its code.

Just started using git some time ago but never ran into troubles like that before. I would really appreciate any help I can get :s

Michael Kargl
  • 662
  • 10
  • 21
  • Is git waiting for you to resolve merge conflicts? What does `git status` say? – Steinar Mar 24 '13 at 17:51
  • 1
    If you're willing to nuke your worktree you can `git checkout -f Mk`. – jthill Mar 24 '13 at 18:45
  • @Steinar Yes I think it does.. I get a lot of modified files that do not seem to be modified at all. git diff prints all the files with "old mode 100644 new mode 100755"... I have lost every orientation whatsoever – Michael Kargl Mar 24 '13 at 19:51
  • @jthill Thanks! This is a great way to secure your code if you have to! – Michael Kargl Mar 24 '13 at 20:34

4 Answers4

8

Since there isn't a --theirs strategy (even though there are ways to simulate it), couldn't you:

  • merge first master to mk: git checkout mk && git merge -s ours master
  • the merge mk to master (fast-forward): git checkout master && git merge mk

The -s ours strategy will make sure you keep mk version in case of conflicts.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the reply and references! I'll take a deep look at it. I can't checkout mk because of the error: Your local changes to the following files would be overwritten by checkout. – Michael Kargl Mar 24 '13 at 19:29
  • 2
    @MichaelKargl if you have local changes, stash them first (git stash: http://git-scm.com/docs/git-stash) – VonC Mar 24 '13 at 19:35
  • this is BS. `git help merge` lists `theirs` as a strategy being "opposite of 'ours'" – steve Jul 19 '13 at 01:22
  • 4
    @steve but it *is not* a merge strategy: '`ours`' and '`theirs`' are listed as **parameter of the '`recursive`' merge strategy**. With the caveat: "This should not be confused with the `ours` merge strategy, which does not even look at what the other tree contains at all. It discards everything the other tree did, declaring our history contains all that happened in it". There is indeed a separate '`ours`' merge strategy. But as far as I know, there is no '`theirs`' merge strategy. – VonC Jul 19 '13 at 06:59
  • Sorry I guess I was just mad at the naming choices in git itself. I've since figured out an approach I prefer, which is rather simple and I have [shared below](http://stackoverflow.com/questions/15601842/git-wont-let-me-merge/18155444#18155444). Not sure why I didn't think of it before. – steve Aug 09 '13 at 20:51
5

Be sure, you are on a clean working copy of MASTER.

git merge -s recursive -X theirs Mk
Georg
  • 51
  • 1
  • 1
0

I have no idea how but the file permissions got changed for some files of the master branch.

git diff:

diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig
old mode 100644
new mode 100755

I committed the changes made:

git commit --all -m "changes permissions from 644 to 755"

After that I was able to merge the branch as if nothing ever happened

git merge Mk 

Although I know this is not the most elegant solution.. But I am glad to have my code back! Now I only have to figure out how to reverse this permission change. Thanks for the great help though!

Michael Kargl
  • 662
  • 10
  • 21
  • Interesting feedback. +1 A better ft for your particular situation than my answer, I suppose. – VonC Mar 24 '13 at 20:48
0

error: Your local changes to the following files would be overwritten by merge

This is typically because you have uncommitted changes that would be overwritten. So first you need to deal with that by either (1) committing or (2) stashing:

git add .; git commit -m "committing my workz"
# or
git add.; git stash

Now try the merge. Maybe you have conflicts. You want all the changes from mk to take precedence over whatever is in master, because git is a little too sensitive about detecting conflicts sometimes (eg, no real conflicts), or because whomever was committing to master was a dunce:

git checkout master
git merge mk
# oh noes! merge conflicts
# CONFLICT (content): Merge conflict in foo_bar.txt
git checkout mk -- foo_bar.txt
git commit

BOOM! Screw master. You ain't my master.

Note: git checkout is normally used to repoint HEAD (and update your working directory) to a branch/tag/SHA/whatever, but if you do git checkout SHA -- file it won't repoint your HEAD, instead it will update the file you pass after the -- to reflect that file/path content in the SHA you pass. You can pass a path instead of exact file and it will checkout all files that are different in that path.

steve
  • 3,276
  • 27
  • 25