Git won't let me merge

自作多情 提交于 2019-12-04 09:51:24
VonC

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.

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

git merge -s recursive -X theirs Mk

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!

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!