git 一直无法push的解决办法

情况是这样的,我在修改完本地的代码之后 执行 add   commit 这个时候应该可以push,然后我push了一下,然后命令行告诉我并没有修改任何内容,然后我刷新我的github的仓库也没有反应,的确push 失败了,然后我就再次重复上面的步骤 一次,发现还是不行,但是步骤并没有错,而且内容的确修改了,然后我git status了一下 这是显示的状态:

$ git status
HEAD detached from b735284
nothing to commit, working directory clean
然后我看了一下远程库中的版本的确是 b735284 ,然后我通过checkout修改了一下head还是不行,还是有这个问题,最后我在googlg上看到了一个外国大牛的解决办法,其实是我的分支出了问题,一试就成功了:   原文链接

$ git commit rear-release-notes.txt
# HEAD detached from rear-1.16

I had now commits in a branch named:

$ git branch
* (detached from rear-1.16)
  master

Ok, so I went back to the master branch:

$ git checkout master
Warning: you are leaving 2 commits behind, not connected to
any of your branches:

  e9abc7a push release notes 1.16 (again)
  2f5d3fd adding the release notes for 1.16 to doc/

If you want to keep them by creating a new branch, this may be a good time
to do so with:

 git branch new_branch_name e9abc7a

Switched to branch 'master'

Then I executed the following steps with a temporary branch temp to get the missing commits back into the master branch.

$ git branch temp e9abc7a
$ git checkout temp
Switched to branch 'temp'
$ git branch
  master
* temp
$ git log --graph --decorate --pretty=oneline --abbrev-commit master origin/master temp
* e9abc7a (HEAD, temp) push release notes 1.16 (again)
* 2f5d3fd adding the release notes for 1.16 to doc/
* 4581e52 (tag: rear-1.16, origin/master, origin/HEAD, master) prepare rear for new release 1.16
*   de337d4 Merge pull request #403 from ypid/df-encfs-fix

$ git diff master temp
diff --git a/doc/rear-release-notes.txt b/doc/rear-release-notes.txt
....

$ git diff origin/master temp
diff --git a/doc/rear-release-notes.txt b/doc/rear-release-notes.txt
....
$ git branch -f master temp
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
$ git push
$ git branch -d temp
Deleted branch temp (was e9abc7a).


你可能感兴趣的:(Git)