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
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:
Now try the merge. Maybe you have conflicts. You want all the changes from
mk
to take precedence over whatever is inmaster
, because git is a little too sensitive about detecting conflicts sometimes (eg, no real conflicts), or because whomever was committing tomaster
was a dunce:BOOM! Screw
master
. You ain't my master.Note:
git checkout
is normally used to repointHEAD
(and update your working directory) to a branch/tag/SHA/whatever, but if you dogit checkout SHA -- file
it won't repoint yourHEAD
, 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.Since there isn't a
--theirs
strategy (even though there are ways to simulate it), couldn't you:git checkout mk && git merge -s ours master
git checkout master && git merge mk
The
-s ours
strategy will make sure you keepmk
version in case of conflicts.Be sure, you are on a clean working copy of MASTER.
I have no idea how but the file permissions got changed for some files of the master branch.
git diff:
I committed the changes made:
After that I was able to merge the branch as if nothing ever happened
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!