我有只有一个文件的回购程序 (一个木星笔记本文件)。由于该文件是使用Google创建的,因此它不存在于我的本地回购中,而仅存在于我的GitHub回购上。
我只是添加了一个自述文件,并试图从我的本地回购推到GitHub。但由于远程回购领先于我的本地回购,我无法推动后承诺。
然后我决定拉,但由于我不熟悉语法,所以我没有在git pull之后指定任何参数。然后我再次尝试使用git pull origin master,但是现在我收到了一条错误消息,上面写着有一个bug,回购名称改为“主合并”...I知道我可能需要将遥控器拉到一个新的本地分支中,并将它与我的主分支合并,但是我不知道如何在这里完成它,而且我也害怕把整个事情搞砸.谢谢你的建议!
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)
$发布于 2018-12-18 19:17:45
所发生的情况是,当分支位于remote后面时,您已经在本地对它进行了更改。因此,当您在本地提交时,您创建了一个与远程服务器上提交顺序不同步的新引用。
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发布于 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将撤销对您的文件进行的任何未经修改的更改!
https://stackoverflow.com/questions/53838654
复制相似问题