首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拉不上Git后无法推开

拉不上Git后无法推开
EN

Stack Overflow用户
提问于 2018-12-18 17:59:12
回答 2查看 803关注 0票数 0

我有只有一个文件的回购程序 (一个木星笔记本文件)。由于该文件是使用Google创建的,因此它不存在于我的本地回购中,而仅存在于我的GitHub回购上。

我只是添加了一个自述文件,并试图从我的本地回购推到GitHub。但由于远程回购领先于我的本地回购,我无法推动后承诺。

然后我决定拉,但由于我不熟悉语法,所以我没有在git pull之后指定任何参数。然后我再次尝试使用git pull origin master,但是现在我收到了一条错误消息,上面写着有一个bug,回购名称改为“主合并”...I知道我可能需要将遥控器拉到一个新的本地分支中,并将它与我的主分支合并,但是我不知道如何在这里完成它,而且我也害怕把整个事情搞砸.谢谢你的建议!

代码语言:javascript
复制
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)
$
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-18 19:17:45

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

代码语言:javascript
复制
origin/master: * -> * -> *
local/master:  \__ -> your commit

如果您只需要一次提交,请查看一个新分支以保存当前状态

代码语言:javascript
复制
git checkout -b temp-updates

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

提交166a17b4852f5b83a09c3198169d86959a68e3dd

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

代码语言:javascript
复制
git checkout master
git reset --hard origin/master

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

代码语言:javascript
复制
git cherry-pick 166a17b4852f5b83a09c3198169d86959a68e3dd

现在你应该能干净利落地推

代码语言:javascript
复制
git push origin master
票数 1
EN

Stack Overflow用户

发布于 2018-12-18 19:30:34

git pull等于git fetch + git 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将撤销对您的文件进行的任何未经修改的更改!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53838654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档