我想重现由于我对this question的企图答案而导致的问题。在git pull --rebase过程中会怎样让git删除本地文件?
总之
一个github上用户试图做git pull --rebase
和用户的本地文件被删除。我试图在github上重新创建这个场景,但在我的情况下没有任何东西被删除。
那么,怎样才能重现我这里的git拉是破坏性的场景?
细节
1部分:
- 用户问到如何本地更改到新创建的远程仓库同步。
git push
失败,因为用户没有进行远程更改(如预期)。- 我建议使用
git pull --rebase
,然后再解析,然后再git push
。 - 但我的建议导致用户的本地文件被删除。 (请参阅original question)
- 请注意,文件被跟踪(本地提交),因此用户能够恢复它们。
第2部分:
- 我创建了一个名为回购HTTPS://github.com/user/myrepo,自述初始化和的.gitignore
地方,我所做的:
初始化回购本地
> mkdir myrepo > cd myrepo > echo AAAAA > fileA.txt > echo BBBBB > fileB.txt > echo ignoreme > .gitignore > git init
犯下的文件在本地
> git add . > git commit -m"initial commit"
试图把远程改变
> git remote add origin https://github.com/user/myrepo.git > git branch --set-upstream-to=origin/master master > git pull --rebase
的结果(如预期):
First, rewinding head to replay your work on top of it... Applying: initial commit Using index info to reconstruct a base tree... Falling back to patching base and 3-way merge... Auto-merging .gitignore CONFLICT (add/add): Merge conflict in .gitignore error: Failed to merge in the changes. Patch failed at 0001 initial commit The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".
在这一点上,如果我做
ls
,我的本地文件仍在我的文件系统上。> ls -a . .. .git .gitignore README.md fileA.txt fileB.txt
更新:
这里是谁的问题,原来的用户评论。
从user7342807:
...我今天早上安装WordPress正是这一点做到了。
git init git add . git commit -m "initial commit"
在这一点上,我已经意识到我已经创建GitHub的页面 它,在它默认的自述。
所以,不知道这会是一个问题,我试图将作为
git remote add origin http://github.com/user/repo.git git push -u origin master
这是我收到的消息:
$ git push -u origin master To https://github.com/user/project.com ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/user/project.com' 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.
所以,与其力推和擦除该在github上README文件,我 做
git pull --rebase
和git向我展示了这条消息First, rewinding head to replay your work on top of it...
我等了大约5分钟,之前我
ctrl+C
出来的过程中,和 意识到有大约8-9文件从WordPress的网站删除。git status
也显示我删除的文件。我能够恢复使用
git reflog
这表明我的那些文件 我第一次提交的HEAD @ 1,我恢复与git reset --hard "[email protected]{5}"
我的文件
什么可能使他们从删除的文件另一个用户的本地文件系统?
请注意,有一个similar question询问如何在发生这种情况时取消删除文件。所以这种情况发生,人们正在丢失他们的文件。
难道事件删除*未跟踪*文件?我问,因为有多种合并策略可用于git,并且由于您现在正处于合并冲突的中间,如果git认为处理冲突的最佳方式是尝试合并其他方式,它可能会已经从本地远程检出变更集,并试图合并到该变更集上。这样看起来文件被删除,但实际上你仍然处于合并冲突的中间。另外,rebase会一次一个地重放变更集,这可能可以解释这一点。 –
这些是被跟踪的文件。他们一直在犯。我会更新这个问题。 –
@ LasseV.Karlsen这将是有趣的创造可能导致混帐使用这种反向合并策略文件...我看到你关于衍合点为好,但在这种情况下,我相信,只有一个单一的从提交造成在github repo上使用README + .gitignore的git init。 –