Why can’t you merge in a bare git repo?

回眸只為那壹抹淺笑 提交于 2019-12-22 09:13:51

问题


Why can’t I merge into a bare repo? Bare repos don’t have a HEAD or a working tree. In the config file we can see bare=true.

You also can’t pull in a bare repo (because pull = fetch & merge and merge doesn't work). However, you can push to a bare repo – why? As far as I know, push also contains a merge, but in this case we can do it well.

So, the question could be “how does git merge work?”. Why does it need a HEAD? What is it doing when merging?


回答1:


As Chronial points out, pushing does fast-forward merges or forced updates, which just moves references/branch pointers to a different commit.

In an actual non-fast-forward merge, you need a working copy in the case that you get conflicts that you need to resolve. It's been mentioned before by other Stack Overflow users; for example, see this answer (emphasis mine):

git performs all merge-y operations (real merges, cherry-picks, rebases, patch application) on the work tree. This is mentioned several times before, for example in one of the knowledgeable Jakub Narębski's answers:

There is no way that merge (or rebase) can work without touching the working directory (and index), as there can be merge conflicts that have to be resolved using working directory (and/or index).



来源:https://stackoverflow.com/questions/18498241/why-can-t-you-merge-in-a-bare-git-repo

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