git pull --rebase过程中会怎样让git删除本地文件? [英] What would make git delete local files during git pull --rebase?
问题描述
我试图重现由于我对此问题的尝试答案而导致的问题。
简而言之
github用户试图做 git pull --rebase
并且该用户的本地文件已被删除。我试图在github上重新创建这个场景,但是在我的情况下没有任何东西被删除。
那我该如何重现git pull具有破坏性的场景呢? b
$ b
详情
第1部分:
- 用户询问如何将本地更改与新创建的远程存储库同步。
-
git push
失败,因为用户没有进行远程更改(按预期)。 - 我建议使用
git pull --rebase
,然后解析,然后再次git push
。 - 但是我的建议导致用户的本地文件被删除。
(参见 - 我创建了一个名为https的回购://github.com/user/myrepo,用README和.gitignore初始化
-
我做了:
本地初始化回购
> mkdir myrepo
> cd myrepo
>回声AAAAA> fileA.txt
>回波BBBBB> fileB.txt
> echo ignoreme> .gitignore
> git init
在本地提交文件
> git add。
> git commit -minitial commit
尝试拉远程更改
> git remote add origin https://github.com/user/myrepo.git
> git branch --set-upstream-to = origin / master master
> git pull --rebase
-
结果是(如预期):
首先,倒带头重放你的作品......
应用:初始提交
使用索引信息重新构建一个基础树...
回退到补丁库和3路合并...
自动合并.gitignore
CONFLICT(添加/添加):合并冲突.gitignore
错误:未能在更改中合并。
补丁失败时,为0001 initial commit
失败补丁的副本位于:.git / rebase-apply / patch
当您解决此问题时,运行 git rebase --continue。
如果您不想跳过此修补程序,请运行git rebase --skip。
要检出原始分支并停止重新绑定,请运行git rebase --abort。
-
此时,如果我做了
ls
,我的本地文件仍然在我的文件系统中。> ls -a
。 .. .git .gitignore README.md fileA.txt fileB.txt
第2部分:
b
更新:
以下是有问题的原始用户的评论。
from user7342807:
...今天早上我安装了wordpress并做了这个。
git init
git add。
git commit -m初始提交
此时,我已经意识到我已经为
创建github页面,并在其中添加默认自述文件。
所以,不知道这会是一个问题,我试图推行为
git remote add origin http://github.com/user/repo.git
git push -u origin master
这是当我收到消息时:
$ git push -u origin master
到https://github.com/user/project.com
! [被拒绝] master - > master(获取第一个)
错误:未能将某些参考文献推送到'https://github.com/user/project.com'
提示:更新被拒绝,因为远程包含您执行的工作
提示:不在本地。这通常是由另一个存储库推动
hint:引起的。在再次推送之前,您可能需要先集成远程更改
提示:(例如,'git pull ...')。
提示:有关详细信息,请参阅'git push --help'中的'关于快速转发的注意事项'。
因此,我不是强制推送和擦除github上的README文件,而是
git pull --rebase
和git向我显示了这条消息
首先,倒带头重播你的工作...
我等了大约5分钟,在我
ctrl + C
出了进程,
意识到有大约8-9个文件从wordpress网站中删除。
git status
也向我展示了删除的文件。
我能够使用
git reflog
来恢复这些文件,它显示我
我的第一次提交在HEAD @ 1,我用恢复了我的文件git reset
--hardHEAD @ {5}
可能导致文件从其他用户的本地文件系统中删除?
<请注意,有一个类似的问题,要求如何在发生这种情况时取消删除文件。因此,这种情况发生,人们正在丢失他们的文件。
我无法评论,因为低回购,但我安装了wordpress今天早上做了这个。
git init
git add。
git commit -m初始提交
此时,我已经意识到我已经为它创建了github页面,并在其中包含默认自述文件。
所以,不知道这会是一个问题,我试图推行为
git remote add origin http://github.com/user/repo.git
git push -u origin master
这是当我收到消息时:
$ git push -u origin master
到https://github.com/user/project.com
! [被拒绝] master - > master(获取第一个)
错误:未能将某些参考推送到'https://github.com/user/project.com'
提示:由于远程包含的工作是
提示:不在本地。这通常是由另一个存储库推动
hint:引起的。在再次推送之前,您可能需要先集成远程更改
提示:(例如,'git pull ...')。
提示:有关详细信息,请参阅'git push --help'中的'关于快速转发的注意事项'。
因此,我不是在github上强制推送和擦除README文件,而是 git pull --rebase
和git向我显示了这条消息
首先,倒带头重放你的在它上面工作...
我等了大约5分钟,在我 ctrl + C
出来的过程,并意识到有大约8-9文件从WordPress的网站删除。 git status
也向我展示了删除的文件。
我能够使用 git reflog
来恢复这些文件,这表明我在HEAD @ 1和I上第一次提交用恢复我的文件git reset --hardHEAD @ {5}
I am trying to reproduce a problem that resulted from my attempted answer to this question.
In short
A github user tried to do git pull --rebase
and that user's local files were deleted. I have tried to recreate this scenario on github but in my case nothing is deleted.
So how can I reproduce the scenario where git pull is destructive?
The details
Part 1:
- A user asked how to synchronize local changes to a newly-created remote repository.
git push
failed because the user did not have remote changes (as expected).- I suggested to use
git pull --rebase
, then resolve, thengit push
again. - But my suggestion resulted in the user's local files being deleted. (see original question)
- note that the files were tracked (committed locally), so the user was able to restore them.
Part 2:
- I created a repo called https: //github.com/user/myrepo, initialized with README and .gitignore
locally, I did:
initialized repo locally
> mkdir myrepo > cd myrepo > echo AAAAA > fileA.txt > echo BBBBB > fileB.txt > echo ignoreme > .gitignore > git init
committed the files locally
> git add . > git commit -m"initial commit"
tried to pull remote changes
> git remote add origin https://github.com/user/myrepo.git > git branch --set-upstream-to=origin/master master > git pull --rebase
the result was (as expected):
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".
At this point, if I do
ls
, my local files are still on my filesystem.> ls -a . .. .git .gitignore README.md fileA.txt fileB.txt
Update:
Here is a comment from the original user who had the problem.
from user7342807:
... I installed wordpress this morning and did exactly this.
git init git add . git commit -m "initial commit"
at this point, I had realized I already created the github page for it, WITH a default readme in it.
So, not knowing this would be an issue, I tried to push as
git remote add origin http://github.com/user/repo.git git push -u origin master
This is when I received the message:
$ 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.
So, instead of force pushing and erasing that README file on github, I did
git pull --rebase
and git showed me this messageFirst, rewinding head to replay your work on top of it...
I waited about 5 minutes, before I
ctrl+C
out of the process, and realized there were about 8-9 files removed from the wordpress site.git status
also showed me the removed files.I was able to recover those files using
git reflog
which showed me my first commit on HEAD@1 and I recovered my files withgit reset --hard "HEAD@{5}"
What could have caused the files to be deleted from the other user's local filesystem?
Please note that there is a similar question that asks how to un-delete files when this happens. So this case occurs and people are losing their files.
I can't comment due to low repo, but I installed wordpress this morning and did exactly this.
git init
git add .
git commit -m "initial commit"
at this point, I had realized I already created the github page for it, WITH a default readme in it.
So, not knowing this would be an issue, I tried to push as
git remote add origin http://github.com/user/repo.git
git push -u origin master
This is when I received the message:
$ 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.
So, instead of force pushing and erasing that README file on github, I did git pull --rebase
and git showed me this message
First, rewinding head to replay your work on top of it...
I waited about 5 minutes, before I ctrl+C
out of the process, and realized there were about 8-9 files removed from the wordpress site. git status
also showed me the removed files.
I was able to recover those files using git reflog
which showed me my first commit on HEAD@1 and I recovered my files with git reset --hard "HEAD@{5}"
这篇关于git pull --rebase过程中会怎样让git删除本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!