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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:27:32  来源:igfitidea点击:

Git push won't do anything (everything up-to-date)

gitdvcs

提问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 pushdoesn'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 originit 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 masterwithout worrying about all this!

问:但我可以master不担心这一切!

When you git clone, by default it sets up your local masterbranch to push to the remote's masterbranch (locally referred to as origin/master), so if you only commit on master, then a simple git pushwill 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 pushwithout 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 developinto origin/master, then you should probably merge them into your local masterthen push that:

如果您想要做的是将您的更改从developinto 放入origin/master,那么您可能应该将它们合并到您的本地master然后推送:

git checkout master
git merge develop
git push             # will push 'master'

If what you want is to create a developbranch 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 developbranch; andset developto push to origin/developso that in future, git pushwithout arguments willpush developautomatically.

这将:在名为的远程上创建一个新分支develop把该分支最新的与您当地的develop分公司; develop推向origin/develop这样,未来,git push没有参数develop自动。

If you want to push your local developto 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 developto always push to origin/something-elsein future; it's a one-shot operation.

但是,该表单不会设置developorigin/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 addhad 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 pushwill work once it knows about a develop branch on your origin.

现在,它看起来就像您在开发分支上一样。你的起源有一个开发分支吗?如果没有,请尝试git push origin developgit 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 ^Cin the middle of a git pushto GitHub. GitHub did not show that the changes had been made, however.

当我^Cgit pushGitHub中间时,这发生在我身上。但是,GitHub 并未显示已进行更改。

To fix it, I made a change to my working tree, committed, and then pushed again. It worked perfectly fine.

为了修复它,我对我的工作树进行了更改,提交,然后再次推送。它工作得很好。