简体   繁体   English

Git 取/拉混淆

[英]Git Fetch/Pull confusion

I am a newbie in git and currently trying out various combinations to understand git.我是 git 的新手,目前正在尝试各种组合来理解 git。

I have a repository with branch named 'dev'.我有一个名为“dev”的分支的存储库。 Now initially i brought my local in sync with the remote.现在最初我使我的本地与遥控器同步。 Then i changed the remote directly from Github.然后我直接从 Github 更改了遥控器。

Now if i use现在如果我使用

git fetch origin dev:dev

then i receive an error然后我收到一个错误

fatal: Refusing to fetch into current branch refs/heads/dev of non-bare repository

However, the following pull command works fine但是,以下 pull 命令工作正常

git pull origin dev

In one of the Stackoverflow answer it was mentioned that fetch followed by merge was equivalent to git pull.在 Stackoverflow 的其中一个答案中提到,fetch 后跟 merge 等效于 git pull。

If it is so then why this discrepency ?如果是这样,那么为什么会出现这种差异?

Question Link : understanding git fetch then merge问题链接: 理解 git fetch 然后合并

PS : The answer suggested from link below in comments is correct one. PS:从下面评论中的链接建议的答案是正确的。 However i was wondering that但是我想知道

git fetch origin 

fetches from all branches including the current one.从包括当前分支在内的所有分支中获取。 Then why perform the check only in case of那么为什么只在以下情况下执行检查

git fetch origin master:master

I am not able to understand the reason behind this validation.我无法理解此验证背后的原因。 Any help is appreciated.任何帮助表示赞赏。

Thanks谢谢

fatal: Refusing to fetch into current branch refs/heads/dev of non-bare repository致命:拒绝获取到非裸存储库的当前分支 refs/heads/dev

This error generally means that you're fetching a branch that doesn't have a remote branch.此错误通常意味着您正在获取一个没有远程分支的分支。 I'm making some assumptions here that you want to fetch from the origin repo and merge in the latest changes from dev to your local branch.我在这里做了一些假设,您希望从origin库中获取并合并从dev到本地分支的最新更改。 If this is the case, then you want to try out following :如果是这种情况,那么您想尝试以下操作:

git fetch origin
git merge origin/dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM