简而言之
github用户尝试执行此操作git pull --rebase,该用户的本地文件被删除。我试图在github上重新创建此方案,但就我而言,什么也没有删除。
那么,如何重现git pull具有破坏性的场景?
细节
第1部分:
git push 失败,因为用户没有远程更改(按预期方式)。git pull --rebase,然后解决,然后git push再次使用。第2部分:
在本地,我做了:
本地初始化回购
> mkdir myrepo
> cd myrepo
> echo AAAAA > fileA.txt
> echo BBBBB > fileB.txt
> echo ignoreme > .gitignore
> git init
Run Code Online (Sandbox Code Playgroud)
在本地提交文件
> git add .
> git commit -m"initial commit"
Run Code Online (Sandbox Code Playgroud)
试图拉远程更改
> git remote add origin https://github.com/user/myrepo.git
> git branch --set-upstream-to=origin/master master
> git pull --rebase
Run Code Online (Sandbox Code Playgroud)结果是(按预期):
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".
Run Code Online (Sandbox Code Playgroud)此时,如果我这样做了ls,我的本地文件仍在我的文件系统上。
> ls -a
. .. .git .gitignore README.md fileA.txt fileB.txt
Run Code Online (Sandbox Code Playgroud)更新:
这是有问题的原始用户的评论。
来自user7342807:
...今天早上我安装了wordpress并做到了这一点。
Run Code Online (Sandbox Code Playgroud)git init git add . git commit -m "initial commit"在这一点上,我意识到我已经为它创建了github页面,其中包含默认自述文件。
因此,我不知道这会是一个问题,所以我试图推动
Run Code Online (Sandbox Code Playgroud)git remote add origin http://github.com/user/repo.git git push -u origin master这是我收到消息的时间:
Run Code Online (Sandbox Code Playgroud)$ 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 --rebasegit向我显示了此消息Run Code Online (Sandbox Code Playgroud)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 "HEAD@{5}"
是什么原因导致文件从另一个用户的本地文件系统中删除?
请注意,有一个类似的问题,询问在这种情况下如何取消删除文件。因此,发生这种情况,并且人们正在丢失其文件。
| 归档时间: |
|
| 查看次数: |
1118 次 |
| 最近记录: |