git fetch 不会更新我的本地存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9841433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git fetch doesn't update my local repository
提问by Rodrigo
What I want:
我想要的是:
Update all news commits from server with my local repository in all branch but do not merge any branch (just join the history lines).
使用我在所有分支中的本地存储库更新来自服务器的所有新闻提交,但不要合并任何分支(只需加入历史记录行)。
I am trying this command
我正在尝试这个命令
git fetch --force --progress --verbose name@host:/path/to/repository.git
I thought it will work fine, because it show:
我认为它会正常工作,因为它显示:
From host:/path/to/repository
* branch HEAD -> FETCH_HEAD
But, what means this output? If I see the log, it wasn't update. If I do a clone from server, all new commits are there. So... The command not work. Then I try with a branch that exist in server but not in my local repository
但是,这个输出是什么意思?如果我看到日志,它没有更新。如果我从服务器进行克隆,则所有新提交都在那里。所以...命令不起作用。然后我尝试使用服务器中存在但不在本地存储库中的分支
git fetch --force --progress --verbose name@host:/path/to/repository.git my_branch
The result is:
结果是:
From host:/path/to/repository
* branch my_branch -> FETCH_HEAD
And any success... Even if I not know all branches and my branch was update, I want to fetch this changes and can see in my log.
任何成功......即使我不知道所有分支并且我的分支是更新的,我想获取这些更改并且可以在我的日志中看到。
Any idea to do it work?
有什么想法可以做到吗?
回答by George Skoptsov
When you fetch you get the remote branches, but you still need to merge the changes from the remote branch into your local branch to see those changes.
当您获取远程分支时,您仍然需要将远程分支中的更改合并到本地分支中以查看这些更改。
After fetching, try this:
获取后,试试这个:
git log origin/yourbranchname | head
git log yourbranchname | head
Do you see the difference?
你看得到差别吗?
Now do:
现在做:
git checkout origin/yourbranchname -b newbranchname
git log newbranchname
You should see remote changes in the newbranchname.
您应该会在新分支名称中看到远程更改。
You can also merge those changes into your branch with
您还可以将这些更改合并到您的分支中
git checkout yourbranchname
git merge origin/yourbranchname
回答by kext
I faced this issue before, the main reason is that you didn't config the remote.origin.fetch in your git local config.
我之前遇到过这个问题,主要原因是你没有在你的 git 本地配置中配置 remote.origin.fetch。
use below command to fix your issue:
使用以下命令来解决您的问题:
git config --local --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
after that, run 'git fetch origin', i think you will get the expected output.
之后,运行'git fetch origin',我想你会得到预期的输出。
回答by John Weldon
git fetch
just brings the changes to the local copy of the remote branch. If you want to update your repo or local branch you have to follow the fetch
with a merge
, or else just use git pull
for one-shot.
git fetch
只是将更改带到远程分支的本地副本。如果您想更新您的回购或地方分支机构,你必须遵循的fetch
一个merge
,或者只使用git pull
了一杆。
Great SO answer: https://stackoverflow.com/a/292359/102371