无法成功拉入Git后无法推动

时间:2018-12-18 17:59:12

标签: git github

我有a repo that has only one file(Jupyter笔记本文件)。由于该文件是使用Google Colab创建的,因此它在我的本地存储库中不存在,而仅在我的GitHub存储库中。

我刚刚添加了一个README文件,并试图将其从本地存储库推送到GitHub。但是由于远程回购要早于本地回购,因此提交后我无法推送。

然后我决定退出,但是由于我不熟悉语法,因此在git pull之后没有指定任何参数。然后我再次尝试使用git pull origin master,但是现在我收到一条错误消息,指出存在错误,并且回购名称更改为“ master | MERGING” ...我知道我可能需要将遥控器拉到新的本地分支并与我的主分支合并,但是我不知道如何在这里做,而且也不敢弄乱整个事情……谢谢任何提示!

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git commit -m "Add README file"
[master 13c0b76] Add README file
 1 file changed, 16 insertions(+)
 create mode 100644 README.md

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git push origin master
To https://github.com/georgeliu1998/tf_and_colab.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/georgeliu1998/tf_and_cola                                                                                                                                                                                               b.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git checkout master
Already on 'master'

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git pull
remote: Enumerating objects: 20, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 18 (delta 5), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (18/18), done.
From https://github.com/georgeliu1998/tf_and_colab
   0a500ee..1238317  master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master


georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git push origin master
To https://github.com/georgeliu1998/tf_and_colab.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/georgeliu1998/tf_and_cola                                                                                                                                                                                               b.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git remote
origin

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git pull origin
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master)
$ git pull origin master
From https://github.com/georgeliu1998/tf_and_colab
 * branch            master     -> FETCH_HEAD
hint: Waiting for your editor to close the file... warning: failed to restrict f                                                                                                                                                                                               ile handles (2)

handle #0: 0000000000000434 (type 3, handle info (1) 0
handle #1: 0000000000000438 (type 3, handle info (1) 1

This is a bug; please report it at
https://github.com/git-for-windows/git/issues/new

To suppress this warning, please set the environment variable

        SUPPRESS_HANDLE_INHERITANCE_WARNING=1

error: cannot spawn C:/Users/georg/AppData/Local/atom/bin/atom.cmd: No such file                                                                                                                                                                                                or directory
error: unable to start editor 'C:/Users/georg/AppData/Local/atom/bin/atom.cmd'
Not committing merge; use 'git commit' to complete the merge.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_col                                                                                                                                                                                               ab (master|MERGING)
$ git push origin master
To https://github.com/georgeliu1998/tf_and_colab.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/georgeliu1998/tf_and_colab.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

georg@DESKTOP-9VE7F0E MINGW64 /d/Dropbox/WorkingDir/personal-projects/tf_and_colab (master|MERGING)
$

2 个答案:

答案 0 :(得分:1)

发生的事情是,当分支位于远程后面时,您已在本地对其进行了更改。因此,当您在本地提交时,您创建的新引用与远程服务器上的提交顺序不同步。

origin/master: * -> * -> *
local/master:  \__ -> your commit

如果仅是一次提交,请签出一个新分支以保存当前状态

git checkout -b temp-updates

然后从git log的第一行复制提交哈希

  

提交166a17b4852f5b83a09c3198169d86959a68e3dd

然后切换回master并将其重置为与远程分支相同:

git checkout master
git reset --hard origin/master

现在,您可以通过所做的更改选择提交:

git cherry-pick 166a17b4852f5b83a09c3198169d86959a68e3dd

现在您应该可以干净地按下

git push origin master

答案 1 :(得分:0)

git pull等于git fetchgit merge。如有疑问,请勿致电git pull,而先致电git fetch,然后致电git status,然后停下来想想下一步要做什么。

在您的情况下,后续的git merge试图将来自origin/master的更改与本地master中的更改合并,但这导致了冲突。 git希望您解决冲突,然后git add将文件标记为已解决,然后git merge --continue完成合并。

如果您想中止合并,可以执行git merge --abort返回到正常状态。如果该命令由于任何原因不起作用,则git reset --hard HEAD将清除您的工作目录。 警告git reset --hard将撤消对文件的所有未提交的更改!