git fetch,FETCH_HEAD和origin / master [英] git fetch, FETCH_HEAD and origin/master

查看:225
本文介绍了git fetch,FETCH_HEAD和origin / master的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对git很陌生,并且在简单的 fetch 操作中遇到了麻烦。



我试图从他的存储库中获取同事的进度。起初,我做了 git fetch HEAD ,这促使git下载大约350MB的数据,所以我确信它已经做了一些事情。然而, origin / master 最终仍然指向相同的旧提交(实际上它在名称 dev 下,但我'我将它称为 master - 他没有 master )。

之后,我尝试了 git fetch origin master ,但它似乎没有做任何事情,它只更新了 FETCH_HEAD 。我标记了 FETCH_HEAD 提交,所以我不会失去它,但我仍然想要更新远程分支。



那是什么错误?我无权访问远程存储库。我可以在家里修复它吗?

解决方案

我对你使用的命令有点困惑。 HEAD 通常是git用于跟踪当前在工作目录中的提交的标签。 git fetch 命令需要远程远程提交配置来知道您要获取的内容。使用 git fetch HEAD 会显示 HEAD 是存储库中的远程服务器。



例如: git fetch HEAD 在我目前的版本库中工作结果中出现以下错误:

  fatal:'HEAD'似乎不是git存储库
致命错误:可能不从远程存储库读取。

请确保您拥有正确的访问权限
并存在存储库。

命令 git remote 会列出所有遥控器,而 git remote --verbose 将包含远程地址。你可以用这个来看看你是否有一个远程定义为 HEAD 和你的朋友存储库的远程地址?



但是,我的问题放在一边,并帮助澄清你的困惑。 git fetch ... 命令只会更新远程引用 - 不是您本地的引用。

,查看存储库中的.git文件夹(它默认隐藏,因此您可能需要取消隐藏)。你会发现一个类似于下面的文件夹结构:

 工作目录
| => .git
| | =>对象< =包含每次提交
|的数据| => refs
| | =>头部
| | -master <=包含当地主分支
|的当前提交的文件| =>遥控器
| | =>原产地
| | -master <=包含远程原始主分支的当前提交的文件
| -FETCH_HEAD< =由git fetch更新的文件,包含获取内容的信息

假设您签出master分支, git checkout master - git会将您的工作目录更改为匹配'objects'文件夹中与'.git / refs / heads / master'文件中的提交值相匹配的提交数据。



如果您<,'.git / refs / remotes / origin / master'文件更新为远程源主分支的提交 - 以及所有提交数据该提交被下载并放置在'objects'文件夹中。



这里的重点是 git fetch 不会更新你的工作目录反映了本地分支签出和 git fetch 从不更新本地分支。



使用 git merge ... 或<$需要c $ c> git rebase ... 来更新本地 master 分支,并在 origin / master git pull ... 同时执行 git fetch ... git merge .. 。 git rebase ... ,取决于选项和配置( git merge ... 是默认值)。

完成这个解释之后,您想要看看是否有什么 - 如果有的话 - 是从朋友存储库中提取的。 git branch -avv 命令将列出所有本地和远程分支,提交编号以及本地分支的情况下,它将跟踪哪个远程分支。



要查看分支之间的相互关系,我发现使用工具来绘制存储库树很有帮助。有几种可供选择,但我发现 git log 命令已足够;如 git log --all --graph --oneline --decorate 。公平的警告,这对于一个大型的存储库来说可能会很长并且令人费解。通过添加 - 装饰简化参数可以获得较短的输出。



总结:如果您可以在家修复它,则取决于您存储库中的信息。上面提到的命令; git remote --verbose git branch -avv git log ... 应该让你了解你的仓库的当前状态。从那里你可以确定是否需要使用 git merge git rebase 获取本地分支中的数据。 code>。



与往常一样,如果遇到麻烦,请回复所学知识。


I'm very new to git and I'm having trouble with a simple fetch operation.

I'm trying to fetch a coworker's progress from his repository. At first I did git fetch HEAD which prompted git to download about 350MB of data so I was sure it had done something. However, origin/master ended up still pointing to the same old commit (actually it's under the name dev but I'll call it master - he doesn't have a master).

After that I tried git fetch origin master but it didn't seem to do anything, it only updated FETCH_HEAD. I tagged the FETCH_HEAD commit so I wouldn't lose it, but I'd still like to have an updated remote branch.

What was it that went wrong? I do not have access to the remote repository. Can I still fix it at home?

解决方案

I'm a bit confused by the commands you use. HEAD is usually a label git uses to track the commit that is currently in the working directory. The git fetch command expects a remote or a remote commit configuration to know what you want fetched. Using git fetch HEAD would indicate HEAD is a remote in your repository. That the command worked without error is curious.

For example: git fetch HEAD in the repository I'm currently working results in the following error

fatal: 'HEAD' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

The command git remote will list all remotes, while git remote --verbose will include the address of the remote. Could you use this to see if you have a remote defined as HEAD and what remote addresses your friends repository?

However, my questions aside and to help clear up your confusion. The git fetch ... command only updates remote refs -- not your local ones.

To make this clear, look inside the .git folder in your repository (it is hidden by default so you may need to unhide it). You will find a folder structure similar to the following

working directory
|=>.git
|  |=>objects           <= contains data for each commit
|  |=>refs
|     |=>heads
|        |-master       <= file containing current commit of local master branch
|     |=>remotes
|        |=>origin
|           |-master    <= file containing current commit of remote origin's master branch
|-FETCH_HEAD            <= file updated by `git fetch`, contains info of what was fetched

Say you checkout the master branch, git checkout master -- git will change your working directory to match the commit data in the 'objects' folder that matches the commit value in the '.git/refs/heads/master' file.

If you then git fetch origin master, the '.git/refs/remotes/origin/master' file is updated to the commit of the master branch on the remote origin -- and all commit data needed for that commit is downloaded and placed in the 'objects' folder.

The important point here is git fetch does not update your working directory reflects the local branch checked out and git fetch never updates a local branch.

Using either git merge ... or git rebase ... is needed to update the local master branch with the changes in origin/master. git pull ... does both git fetch ... and either git merge ... or git rebase ..., depending on options and configuration (git merge ... is the default).

After all that explanation, you want to be able to see what -- if anything -- was fetched from your friends repository. The git branch -avv command will list all local and remote branches, with commit numbers and in the case of local branches, what remote branch it is tracking.

To see how the branches relate to each other I find it helpful to use a tool to graph the repository tree. There are several to choose from but I find the git log command sufficient; such as git log --all --graph --oneline --decorate. Fair warning, this can be quite long and convoluted for a large repository. A shorter output can be obtained with by adding the --simplify-by-decoration argument.

To summarize: if you can fix it at home depends on the information in your repository. The above mentioned commands; git remote --verbose, git branch -avv and git log ... should be give you an understanding of the current state of your repository. From there you can determine if you need to do something more to get the data in your local branch(es) using git merge or git rebase.

As always, if you run into trouble, post back with what you learn.

这篇关于git fetch,FETCH_HEAD和origin / master的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆