GIT push not pushing commits to remote

岁酱吖の 提交于 2019-12-12 16:08:34

问题


I have been working on a git repository and have been pushing my local changes to a remote server all the time... up until recently. When I do a git push, it says that everything is up-to-date. In reality, I'm already 3 commits ahead of the remote version and it's not getting my changes.

I have tried the git log -1, git reset --hard solution posted on various places, but that doesn't solve anything. Do I need to change that number to reflect the number of commits that I am ahead?

Say I have 5 commits, for brevetys sake named 1 to 5. My local version is at 5, the remote version is at 2. Gitk shows my MASTER at commit 5 and remotes/origin/master at commit 2. Do I need to git reset my local version to 2 (or 3, the first commit that was not pushed to remote)? What will happen to my changes? The git documentation says that --hard will discard any changes, will that mean that they will be lost completely? I would like to keep the commit history of these 3 commits, as there were quite some changes made.


回答1:


I was in the same situation a few minutes ago (which is why I wandered into this thread). Anwyay, I was able to solve it via git push origin master instead of just git push.

This happened after I created a new branch, started pushing to the new branch, then went back to the master branch and tried to push to that branch again.




回答2:


First of all carefully examine your configuration.

  1. Make sure you have pushed it really.
  2. Make sure you have pushed it to where you THINK you pushed it.

What can help you:

$ git log --full-history // is your commit really there?
$ git reflog // operation history
$ git remote -v // what are your remotes? 
$ git remote show DESIRED_REPO // do you have the remote repo you wanted to push to configured? the DESIRED_REPO?

Finally, make sure you are using RIGHT push notation:

  1. There is a difference between git push public and git push --repo=public. First pushes to public ALWAYS, second only if remote for branch you are pushing is not set.
  2. If your branch is named differently than it's remote counterpart, this can make a difference.

$ git push remote local_branch:remote_branch // I've made this error today by swapping places, with remote_branch:local_branch Git will not find the branch to update.

Hope this helps. In my case careful re-reading of manual while re-examining commands I've tried helped and revealed the problem (swapped branch names).



来源:https://stackoverflow.com/questions/16029895/git-push-not-pushing-commits-to-remote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!