Git Pull - 一切都是最新的,但不是
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8350567/
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 Pull - Everything up to date, but it's not
提问by WillHaack
I'm trying to pull from a repository which has about 10 files. On my local repository, I only have one file. When I type
我试图从一个大约有 10 个文件的存储库中提取。在我的本地存储库中,我只有一个文件。当我打字
git pull origin master
I get back "Everything up to date"
我回来了“一切都是最新的”
However, I'm still missing those 9 or so files on the repository. Any ideas as to why this might happen?
但是,我仍然缺少存储库中的那 9 个左右的文件。关于为什么会发生这种情况的任何想法?
采纳答案by Hendrik M Halkow
Check whether you are on the right branch and have checked out the same revision you are comparing to: git checkout HEAD
检查您是否在正确的分支上并检查了您正在比较的相同修订: git checkout HEAD
回答by DrHall
I had a similar problem, but needed a different solution. The local versions on one computer were not getting updated from the GitHub repo, which was ahead based on work I had done and pushed from a second computer the night before. It kept telling me all files were up-to-date, even though clearly the ones on the first computer were not the same as the ones on the second or the GitHub repo.
我遇到了类似的问题,但需要不同的解决方案。一台计算机上的本地版本没有从 GitHub 存储库中更新,这是基于我前一天晚上从第二台计算机上所做的工作而提前的。它一直告诉我所有文件都是最新的,尽管很明显第一台计算机上的文件与第二台或 GitHub 存储库上的文件不同。
What finally fixed this problem for me was adding a trash .txt file on the second computer (new and different from everything else there, so there would be no merge conflicts). I pushed that file to the repo, then made a new attempt to pull from the first. When it saw the new file it made the pull, and took all the other changes as well.
最终为我解决这个问题的是在第二台计算机上添加一个垃圾 .txt 文件(新的并且与那里的其他所有内容不同,因此不会有合并冲突)。我将该文件推送到存储库,然后重新尝试从第一个中提取。当它看到新文件时,它进行了拉取,并进行了所有其他更改。
I'm sure there was a better soltution, and this is something I was doing wrong with git, but since it worked I wanted to post it, in case anyone else is having the problem I was.
我确信有更好的解决方案,这是我在使用 git 时做错的地方,但由于它有效,我想发布它,以防其他人遇到我的问题。
回答by keinabel
For me it worked to pull another branch which was already merged with master.
对我来说,它可以拉出另一个已经与 master 合并的分支。
git checkout master
git pull origin name/of/other/branch
git checkout master
git pull origin name/of/other/branch
回答by John Wooten
I am concerned about these answers as the following console history will show. In brief, I pushed a change to the develop branch on one machine. I ssh'd to another with the same repository and did a git status in the same branch. The status said "Your branch is up to date with 'origin/develop'". YET! When I did a pull, it brought down the change and a previous one that had not been detected. Here is the console history:
我很担心这些答案,因为以下控制台历史记录将显示。简而言之,我在一台机器上对开发分支进行了更改。我通过 ssh 连接到另一个具有相同存储库并在同一分支中执行 git status 的操作。状态显示“您的分支是最新的'origin/develop'”。然而!当我拉动时,它降低了更改和之前未检测到的更改。这是控制台历史记录:
I have liquidprompt installed and it shows the branch I am on.
我安装了liquidprompt,它显示了我所在的分支。
[:~/bin] develop* ± git status
On branch develop
Your branch is up to date with 'origin/develop'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
create-report
nothing added to commit but untracked files present (use "git add" to track)
[:~/bin] develop* ± git add -A
[:~/bin] develop(+0/-0) ± git commit -m "Create a report for a given month"
[develop 8f1fd89] Create a report for a given month
1 file changed, 13 insertions(+)
create mode 100755 create-report
[:~/bin] develop(1) ± git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 552 bytes | 552.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/userid/project.git
c6f5210..8f1fd89 develop -> develop
[:~/bin] develop 3s ± ssh my_server
Last login: Mon Mar 30 20:12:23 2020 from 10.0.1.131
[userid@my_server:~] $ cd bin
[userid@my_server:~/bin] develop 3s ± git status
On branch develop
Your branch is up to date with 'origin/develop'. (THIS CONCERNS ME)
nothing to commit, working tree clean
[userid@my_server:~/bin] develop 5s ± exit
logout
Connection to my_server closed.
[:~/bin] develop 21s ± git_log
8f1fd89 - (HEAD -> develop, origin/develop) Create a report for a given month (18 minutes ago) <userid>
c6f5210 - Added scripts to deal with growl (4 hours ago) <userid>
b828a96 - Merge branch 'develop' of https://github.com/userid/project into develop Bring in changes from my_server (11 hours ago) <userid>
...
[:~/bin] develop ± ssh my_server
Last login: Tue Mar 31 21:35:49 2020 from 10.0.1.131
[userid@my_server:~] $ cd bin
[userid@my_server:~/bin] develop 2s ± ls create*
create_job*. (N.B. there is not a create-report script)
[userid@my_server:~/bin] develop 8s ± git pull
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 2), reused 7 (delta 2), pack-reused 0
Unpacking objects: 100% (7/7), done.
From https://github.com/userid/project
b828a96..8f1fd89 develop -> origin/develop
Updating b828a96..8f1fd89
Fast-forward
brew-update-notifier | 42 ++++++++++++++++++++++++++++++++++++++++++
create-report | 13 +++++++++++++
growlit | 16 ++++++++++++++++
3 files changed, 71 insertions(+)
create mode 100755 brew-update-notifier
create mode 100755 create-report ( N.B. And it appears!)
create mode 100755 growlit
Why is this happening? There was clearly a push to the develop branch and status indicated nothing on the other server, then a pull brought down the pushed files.
为什么会这样?显然有一个推送到开发分支,状态在另一台服务器上没有任何指示,然后拉下推送的文件。
回答by Amol M Kulkarni
git pull
's job is to fetch
new commits and merge
them into the current branch only.
git pull
的工作是fetch
新的提交,并且merge
它们只进入当前分支。
If the current branch is not outdated compared to the one you pull from, pull will say Already up-to-date.
If you have any local changes in your working directory, its ignored sliently (it has nothing to do with this).
如果当前分支与您拉取的分支相比没有过时, pull 会说Already up-to-date.
如果您的工作目录中有任何本地更改,它会被悄悄忽略(与此无关)。
Note:git pull
is concerned only with branch & new commits, not the working tree.
注意:git pull
只关心分支和新提交,而不是工作树。