可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
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?
[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)
回答1:
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.
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:
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!
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.
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.
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:
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
:
git push origin develop
That will: create a new branch on the remote called develop
; and bring that branch up to date with your local develop
branch; and set develop
to push to origin/develop
so that in future, git push
without arguments will push develop
automatically.
If you want to push your local develop
to a remote branch called something other than develop
, then you can say:
git push origin develop:something-else
However, that form won't set up develop
to always push to origin/something-else
in future; it's a one-shot operation.
回答2:
This happened to me when my Sourcetree app crashed during staging. And on the command line, it seemed like the previous git add
had been corrupted. If this is the case, try:
git init git add -A git commit -m 'Fix bad repo' git push
Or 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
回答3:
Try:
git push --all origin
回答4:
Please try going to last commit and then git push origin HEAD:master
回答5:
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.
As further reading, I'd have a look at the git-push man pages, in particular, the examples section.
回答6:
Also make sure your pushing to the correct branch.
回答7:
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. To fix, I made a change to my working tree, committed, and the pushed again. It worked perfectly fine.
回答8:
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 add . git commit -am "my comment" git push
Did the trick. I hope this helps someone, as a "last chance" solution.
回答9:
Thanks to Sam Stokes. According to his answer you can solve the problem with different way (I used this way). After updating your develop directory you should reinitialize it
git init
Then you can commit and push updates to master
回答10:
Instead, you could try this, you don't have to go to master, you can directly force push the changes from your branch itself
As explained above, when you do a rebase, you are changing the history on your branch. As a result, if you try to do a normal git push
after a rebase, Git will reject it because there isn't a direct path from the commit on the server to the commit on your branch. Instead, you'll need to use the -f
or --force
flag to tell Git that yes, you really know what you're doing. When doing force pushes, it is highly recommended that you set your push.default
config setting to simple, which is the default in Git 2.0. To make sure that your config is correct, run:
$ git config --global push.default simple
Once it's correct, you can just run:
$ git push -f
And check your pull request. It should be updated!
Go to bottom of this LINK for more details.
回答11: