Git push 不会做任何事情(一切都是最新的)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2936652/
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 won't do anything (everything up-to-date)
提问by Jamie Wong
I'm trying to update a Git repository on GitHub. I made a bunch of changes, added them, committed then attempted to do a git push
. The response tells me that everything is up to date, but clearly it's not.
我正在尝试更新 GitHub 上的 Git 存储库。我做了一堆更改,添加它们,提交然后尝试做一个git push
. 回复告诉我一切都是最新的,但显然不是。
git remote show origin
responds with the repository I'd expect.
用我期望的存储库响应。
Why is Git telling me the repository is up to date when there are local commits that aren't visible on the repository?
当存储库上不可见的本地提交时,为什么 Git 告诉我存储库是最新的?
[searchgraph] git status
# On branch develop
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# Capfile
# config/deploy.rb
nothing added to commit but untracked files present (use "git add" to track)
[searchgraph] git add .
[searchgraph] git status
# On branch develop
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: Capfile
# new file: config/deploy.rb
#
[searchgraph] git commit -m "Added Capistrano deployment"
[develop 12e8af7] Added Capistrano deployment
2 files changed, 26 insertions(+), 0 deletions(-)
create mode 100644 Capfile
create mode 100644 config/deploy.rb
[searchgraph] git push
Everything up-to-date
[searchgraph] git status
# On branch develop
nothing to commit (working directory clean)
回答by Sam Stokes
git push
doesn't push all of your local branches: how would it know which remote branches to push them to? It only pushes local branches which have been configured to push to a particular remote branch.
git push
不会推送所有本地分支:它如何知道将它们推送到哪些远程分支?它只推送已配置为推送到特定远程分支的本地分支。
On my version of Git (1.6.5.3), when I run git remote show origin
it actually prints out which branches are configured for push:
在我的 Git 版本 (1.6.5.3) 上,当我运行git remote show origin
它时,它实际上会打印出为推送配置的分支:
Local refs configured for 'git push':
master pushes to master (up to date)
quux pushes to quux (fast forwardable)
Q. But I could push to master
without worrying about all this!
问:但我可以master
不担心这一切!
When you git clone
, by default it sets up your local master
branch to push to the remote's master
branch (locally referred to as origin/master
), so if you only commit on master
, then a simple git push
will always push your changes back.
当您git clone
,默认情况下它会设置您的本地master
分支以推送到远程的master
分支(本地称为origin/master
),因此如果您只提交master
,那么简单git push
将始终将您的更改推回。
However, from the output snippet you posted, you're on a branch called develop
, which I'm guessing hasn't been set up to push to anything. So git push
without arguments won't push commits on that branch.
但是,从您发布的输出片段来看,您位于一个名为 的分支上develop
,我猜该分支尚未设置为推送到任何内容。所以git push
没有参数不会在那个分支上推送提交。
When it says "Everything up-to-date", it means "all the branches you've told me how to push are up to date".
当它说“一切都是最新的”时,它的意思是“你告诉我如何推送的所有分支都是最新的”。
Q. So how can I push my commits?
问:那么我怎样才能推送我的提交呢?
If what you want to do is put your changes from develop
into origin/master
, then you should probably merge them into your local master
then push that:
如果您想要做的是将您的更改从develop
into 放入origin/master
,那么您可能应该将它们合并到您的本地master
然后推送:
git checkout master
git merge develop
git push # will push 'master'
If what you want is to create a develop
branch on the remote, separate from master
, then supply arguments to git push
:
如果您想要的是develop
在远程上创建一个分支,与 分开master
,然后向 提供参数git push
:
git push origin develop
That will: create a new branch on the remote called develop
; andbring that branch up to date with your local develop
branch; andset develop
to push to origin/develop
so that in future, git push
without arguments willpush develop
automatically.
这将:在名为的远程上创建一个新分支develop
;并把该分支最新的与您当地的develop
分公司; 并集develop
推向origin/develop
这样,未来,git push
没有参数会推develop
自动。
If you want to push your local develop
to a remote branch called something other thandevelop
, then you can say:
如果您想将本地推develop
送到名为以外的其他内容的远程分支develop
,那么您可以说:
git push origin develop:something-else
However, that form won'tset up develop
to always push to origin/something-else
in future; it's a one-shot operation.
但是,该表单不会设置develop
为origin/something-else
将来始终推送;这是一次操作。
回答by Vik
This happened to me when my SourceTree application crashed during staging. And on the command line, it seemed like the previous git add
had been corrupted. If this is the case, try:
当我的 SourceTree 应用程序在登台期间崩溃时,这发生在我身上。而在命令行上,似乎以前的git add
已损坏。如果是这种情况,请尝试:
git init
git add -A
git commit -m 'Fix bad repo'
git push
On the last command, you might need to set the branch.
在最后一个命令中,您可能需要设置分支。
git push --all origin master
Bear in mind that this is enough if you haven't done any branching or any of that sort. In that case, make sure you push to the correct branch like git push origin develop
.
请记住,如果您还没有进行任何分支或任何此类操作,这就足够了。在这种情况下,请确保推送到正确的分支,例如git push origin develop
.
回答by asandroq
Try:
尝试:
git push --all origin
回答by uruapanmexicansong
Please try going to the last commit and then do git push origin HEAD:master
.
请尝试转到最后一次提交,然后执行git push origin HEAD:master
.
回答by Andrea
For my case, none of other solutions worked. I had to do a backup of new modified files (shown with git status
), and run a git reset --hard
. This allowed me to realign with the remote server. Adding new modified files, and running
就我而言,其他解决方案均无效。我必须备份新修改的文件(用 显示git status
),然后运行git reset --hard
. 这使我能够重新调整远程服务器。添加新的修改文件,并运行
git add .
git commit -am "my comment"
git push
Did the trick. I hope this helps someone, as a "last chance" solution.
做到了。我希望这对某人有所帮助,作为“最后一次机会”的解决方案。
回答by theIV
Right now, it appears as you are on the develop branch. Do you have a develop branch on your origin? If not, try git push origin develop
. git push
will work once it knows about a develop branch on your origin.
现在,它看起来就像您在开发分支上一样。你的起源有一个开发分支吗?如果没有,请尝试git push origin develop
。git push
一旦它知道您的原点上的开发分支,它将起作用。
As further reading, I'd have a look at the git-push man pages, in particular, the examples section.
作为进一步阅读,我会查看git-push 手册页,特别是示例部分。
回答by Manu
To be specific, if you want to merge something to master, you can follow the below steps.
具体来说,如果你想合并一些东西来掌握,你可以按照以下步骤操作。
git add --all // If you want to stage all changes other options also available
git commit -m "Your commit message"
git push // By default when it clone is sets your origin to master or you would have set sometime with git push -u origin master.
It's a common practice in the pull request model create to a new local branch and then push that branch to remote. For that you need to mention where you want to push your changes at remote. You can do this by mentioning remote at the time of push.
这是拉请求模型中的常见做法,创建到一个新的本地分支,然后将该分支推送到远程。为此,您需要提及要远程推送更改的位置。您可以通过在推送时提及 remote 来做到这一点。
git push origin develop // It will create a remote branch with name "develop".
If you want to create a branch other than your local branch name you can do that with the following command.
如果要创建本地分支名称以外的分支,可以使用以下命令进行操作。
git push origin develop:some-other-name
回答by Developer Here
I tried many methods including defined here. What I got is,
我尝试了很多方法,包括这里定义的。我得到的是,
Make sure the name of repository is valid. The best way is to copy the link from repository site and paste in git bash.
Make sure you have commited the selected files.
git commit -m "Your commit here"
If both steps don't work, try
git push -u -f origin master
确保存储库的名称有效。最好的方法是从存储库站点复制链接并粘贴到 git bash 中。
确保您已提交所选文件。
git commit -m "Your commit here"
如果这两个步骤都不起作用,请尝试
git push -u -f origin master
回答by user742102
This happened to me. I just re-committed the changes, and then it pushed.
这发生在我身上。我只是重新提交了更改,然后它推送了。
回答by helsont
This happened to me when I ^C
in the middle of a git push
to GitHub. GitHub did not show that the changes had been made, however.
当我^C
在git push
GitHub中间时,这发生在我身上。但是,GitHub 并未显示已进行更改。
To fix it, I made a change to my working tree, committed, and then pushed again. It worked perfectly fine.
为了修复它,我对我的工作树进行了更改,提交,然后再次推送。它工作得很好。