即使我有本地更改,git push 也会说“所有内容都是最新的”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/999907/
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 push says "everything up-to-date" even though I have local changes
提问by ZelluX
I have a remote gitosis server and a local git repository, and each time I make a big change in my code, I'll push the changes to that server too.
我有一个远程 gitosis 服务器和一个本地 git 存储库,每次我对代码进行重大更改时,我也会将更改推送到该服务器。
But today I find that even though I have some local changes and commit to local repository, when running git push origin master
it says 'Everything up-to-date', but when I use git clone
to checkout files on the remote server, it doesn't contain latest changes. And I have only one branch named "master" and one remote server named "origin".
但是今天我发现即使我有一些本地更改并提交到本地存储库,在运行时git push origin master
它会显示“所有内容都是最新的”,但是当我git clone
用来检出远程服务器上的文件时,它不包含最新的更改. 我只有一个名为“master”的分支和一个名为“origin”的远程服务器。
PS:
This is what git displays when running ls-remote
, I'm not sure whether it helps
PS:这是 git 在运行时显示的内容ls-remote
,我不确定它是否有帮助
$ git ls-remote origin
df80d0c64b8e2c160d3d9b106b30aee9540b6ece HEAD
df80d0c64b8e2c160d3d9b106b30aee9540b6ece refs/heads/master
$ git ls-remote .
49c2cb46b9e798247898afdb079e76e40c9f77ea HEAD
df80d0c64b8e2c160d3d9b106b30aee9540b6ece refs/heads/master
df80d0c64b8e2c160d3d9b106b30aee9540b6ece refs/remotes/origin/master
3a04c3ea9b81252b0626b760f0a7766b81652c0c refs/tags/stage3
回答by VonC
Are you working with a detached headby any chance?
您是否有机会使用独立的头部?
As in:
如:
indicating that your latest commit is not a branch head.
表明您的最新提交不是分支负责人。
$ git log -1
# note the SHA-1 of latest commit
$ git checkout master
# reset your branch head to your previously detached commit
$ git reset --hard <commit-id>
As mentioned in the git checkout
man page(emphasis mine):
如git checkout
手册页中所述(强调我的):
It is sometimes useful to be able to checkout a commit that is not at the tip of one of your branches.
The most obvious example is to check out the commit at a tagged official release point, like this:
有时能够检出不在您的一个分支顶端的提交是很有用的。
最明显的例子是在标记的官方发布点检查提交,如下所示:
$ git checkout v2.6.18
Earlier versions of git did not allow this and asked you to create a temporary branch using the
-b
option, but starting from version 1.5.0, the above command detaches yourHEAD
from the current branch and directly points at the commit named by the tag(v2.6.18
in the example above).You can use all git commands while in this state.
You can usegit reset --hard $othercommit
to further move around, for example.
You can make changes and create a new commit on top of a detached HEAD.
You can even create a merge by usinggit merge $othercommit
.The state you are in while your HEAD is detached is not recorded by any branch (which is natural --- you are not on any branch).
What this means is that you can discard your temporary commits and merges by switching back to an existing branch(e.g.git checkout master
), and a latergit prune
orgit gc
would garbage-collect them.
If you did this by mistake, you can ask the reflog for HEAD where you were, e.g.
早期版本的 git 不允许这样做,并要求您使用该
-b
选项创建一个临时分支,但从 1.5.0 版本开始,上述命令将您HEAD
与当前分支分离并直接指向由标记命名的提交(v2.6.18
在上面的例子)。在此状态下,您可以使用所有 git 命令。
例如,您可以使用git reset --hard $othercommit
进一步移动。
您可以在分离的 HEAD 之上进行更改并创建新提交。
您甚至可以使用git merge $othercommit
.任何分支都不会记录您在 HEAD 分离时所处的状态(这很自然——您不在任何分支上)。
这意味着您可以通过切换回现有分支(例如git checkout master
)来丢弃临时提交和合并,稍后git prune
或git gc
将对其进行垃圾收集。
如果你做错了,你可以向 reflog 询问你所在的 HEAD,例如
$ git log -g -2 HEAD
回答by Laz
Err.. If you are a git noob are you sure you have git commit
before git push
? I made this mistake the first time!
呃.. 如果你是一个 git noob 你确定你git commit
以前有过git push
吗?我第一次犯了这个错误!
回答by Roman Starkov
Maybe you're pushing a new local branch?
也许你正在推动一个新的本地分支?
A new local branch must be pushed explicitly:
必须显式推送新的本地分支:
git push origin your-new-branch-name
Just one of those things about git... You clone a repo, make a branch, commit some changes, push... "Everything is up to date". I understand why it happens, but this workflow is extremely unfriendly to newcomers.
只是关于 git 的其中一件事情......你克隆一个仓库,创建一个分支,提交一些更改,推送......“一切都是最新的”。我理解为什么会发生这种情况,但是这个工作流程对新手来说非常不友好。
回答by camden
My issue was that my local branch had a different name than the remote branch. I was able to push by doing the following:
我的问题是我的本地分支与远程分支的名称不同。我能够通过执行以下操作来推动:
$ git push origin local-branch-name:remote-branch-name
$ git push origin local-branch-name:remote-branch-name
(Credit to https://penandpants.com/2013/02/07/git-pushing-to-a-remote-branch-with-a-different-name/)
(归功于https://penandpants.com/2013/02/07/git-pushing-to-a-remote-branch-with-a-different-name/)
回答by Chris Burbridge
Another situation that is important to be aware of: The sort of default state for git is that you are working in the "master" branch. And for a lot of situations, you'll just hang out in that as your main working branch (although some people get fancy and do other things).
另一个需要注意的重要情况:git 的默认状态是您在“master”分支中工作。并且在很多情况下,您只会将其作为主要工作分支(尽管有些人会喜欢并做其他事情)。
Anyway, that's just one branch. So a situation I might get into is:
无论如何,这只是一个分支。所以我可能会遇到的情况是:
My active branch is actually NOT the master branch. ... But I habitually do the command: git push
(and I had previously done git push origin master
, so it's a shortcut for THAT).
我的活动分支实际上不是主分支。......但我习惯性地执行命令:(git push
我以前做过git push origin master
,所以这是THAT的捷径)。
So I'm habitually pushing the master branch to the shared repo ... which is probably a good clean thing, in my case ...
所以我习惯性地将主分支推送到共享仓库......这可能是一件干净的事情,就我而言......
But I have forgotten that the changes I have been working on are not yet IN the master branch !!!
但是我忘记了我一直在做的更改还没有在 master 分支中!!!
So therefore everytime I try git push
, and I see "Everything up to date", I want to scream, but of course, it is not git's fault! It's mine.
所以因此每次我尝试git push
,看到“一切都是最新的”时,我想尖叫,但当然,这不是 git 的错!这是我的。
So instead, I merge my branch into master, and then do push, and everything is happy again.
所以相反,我将我的分支合并到 master 中,然后执行 push,一切又变得愉快了。
回答by Melchia
$ git push origin local_branch:remote_branch
Explanation
解释
I had the same error & spent hours trying to figure it out. Finally I found it.
What I didn't know is that pushing like this git push origin branch-x
will try to search for branch-x locally then push to remote branch-x.
我有同样的错误并花了几个小时试图弄清楚。最后我找到了。我不知道的是,像这样推送git push origin branch-x
会尝试在本地搜索 branch-x,然后推送到远程 branch-x。
In my case, I had two remote urls. I did a checkout from branch-xto branch-ywhen trying to push from y locally to x remote I had the message everything is up to date which is normal cause I was pushing to x of the second remote.
就我而言,我有两个远程网址。当我尝试从本地 y 推送到 x 远程时,我从分支 x到分支 y进行了结帐,我收到消息,一切都是最新的,这是正常的,因为我正在推送到第二个远程的 x。
Long story short to not fall in this kind of trap you need to specify the source ref and the target ref:
长话短说,为了不落入这种陷阱,您需要指定源引用和目标引用:
$ git push origin local_branch:remote_branch
Update:
更新:
If you have to run this command every time you push your branch, you maybe need to set the upstream between your local & remote branch with the following :
如果每次推送分支时都必须运行此命令,则可能需要使用以下内容设置本地和远程分支之间的上游:
$ git push --set-upstream origin local_branch:remote_branch
Or
或者
$ git push -u origin local_branch:remote_branch
回答by rodmclaughlin
See VonC's answer above - I needed an extra step:
请参阅上面 VonC 的回答 - 我需要一个额外的步骤:
$ git log -1
- note the SHA-1 of latest commit
$ git checkout master
- reset your branch head to your previously detached commit
$ git reset --hard <commit-id>
I did this, but when I then tried to git push remoterepo master
, it said "error: failed to push some refs. To prevent you from losing history, non-fast-forward updates were rejected, Merge the remote changes (e.g. 'git pull') before pushing again."
我这样做了,但是当我尝试这样做时git push remoterepo master
,它说“错误:未能推送一些参考文献。为了防止您丢失历史记录,非快进更新被拒绝,之前合并远程更改(例如'git pull')再推。”
So I did 'git pull remoterepo master', and it found a conflict. I did git reset --hard <commit-id>
again, copied the conflicted files to a backup folder, did git pull remoterepo master
again, copied the conflicted files back into my project, did git commit
, then git push remoterepo master
, and this time it worked.
所以我做了'git pull remoterepo master',它发现了一个冲突。我又做了git reset --hard <commit-id>
一次,将冲突的文件复制到了一个备份文件夹,git pull remoterepo master
再一次,将冲突的文件复制回了我的项目,做了git commit
,然后git push remoterepo master
,这次成功了。
Git stopped saying 'everything is up to date' - and it stopped complaining about 'fast forwards'.
Git 不再说“一切都是最新的”——它不再抱怨“快进”。
回答by samwize
From your git status, you probably has a different situation from mine.
从您的 git 状态来看,您的情况可能与我的不同。
But anyway, here is what happened to me.. I encountered the following error:
但无论如何,这就是发生在我身上的事情..我遇到了以下错误:
fatal: The remote end hung up unexpectedly
Everything up-to-date
The more informative message here is that the remote hung up. Turned out it is due to exceeding the http post buffer size. The solution is to increase it with
这里信息量更大的消息是遥控器挂断了。原来这是由于超过了 http 发布缓冲区大小。解决方案是增加它
git config http.postBuffer 524288000
git config http.postBuffer 524288000
回答by Srikanth Kyatham
I have faced a similar situation; when I made the changes and tried to
git push origin master
, it was saying everything was up to date.
我也遇到过类似的情况;当我进行更改并尝试更改时
git push origin master
,它说一切都是最新的。
I had to git add
the changed file and then git push origin master
. It started working from then on.
我不得不git add
更改文件,然后git push origin master
. 从那时起它就开始工作了。
回答by Noah
I had this problem today and it didn't have anything to do with any of the other answers. Here's what I did and how I fixed it:
我今天遇到了这个问题,它与任何其他答案都没有任何关系。这是我所做的以及我如何修复它的:
A repository of mine recently moved, but I had a local copy. I branched off of my local "master" branch and made some changes--and then I remembered that the repository had moved. I used git remote set-url origin https://<my_new_repository_url>
to set the new URL but when I pushed it would just say "Everything up to date" instead of pushing my new branch to master.
我最近移动了一个存储库,但我有一个本地副本。我从本地的“master”分支分支出来并进行了一些更改——然后我记得存储库已经移动了。我曾经git remote set-url origin https://<my_new_repository_url>
设置过新的 URL,但是当我推送它时,它只会说“一切都是最新的”,而不是将我的新分支推送到 master。
I ended up solving it by rebasing onto origin/master
and then pushing with explicit branch names, like this:
我最终通过重新定位origin/master
然后推送显式分支名称来解决它,如下所示:
$ git rebase <my_branch> origin/master
$ git push origin <my_branch>
I hope this helps anyone who had my same problem!
我希望这可以帮助任何遇到我同样问题的人!