是什么会使git在git pult -rebase期间删除本地文件



我正在尝试重现我尝试回答这个问题的问题。

在简短

github用户尝试执行git pull --rebase,并删除了该用户的本地文件。我试图在github上重新创建这种情况,但就我而言,没有删除。

那么,如何重现git拉力破坏性的场景?

详细信息

第1部分:

  • 用户询问如何同步本地更改与新创建的遥控存储库。
  • git push失败了,因为用户没有远程更改(如预期)。
  • 我建议使用git pull --rebase,然后解决,然后再次解决git push
  • 但我的建议导致用户的本地文件被删除。(请参阅原始问题)
  • 请注意,这些文件是在当地跟踪(在本地提交的),因此用户能够还原它们。

第2部分:

  • 我创建了一个名为https://github.com/user/myrepo的仓库,使用readme和.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
    

更新:

这是有问题的原始用户的评论。

来自用户7342807:

...我今天早上安装了WordPress,然后做到了这一点。

git init
git add .
git commit -m "initial commit"

此时,我已经意识到我已经为 它的其中有默认的读数。

所以,不知道这是一个问题,我试图推动

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上推动和擦除该读数文件,而是 git pull --rebase和git向我展示了此消息

First, rewinding head to replay your work on top of it...

我等了大约5分钟,然后才能 ctrl+C conc_7,然后 意识到从WordPress站点中删除了大约8-9个文件。 git status还向我展示了删除的文件。

我能够使用git reflog恢复这些文件 我的第一个提交@1,我用 git reset --hard "HEAD@{5}"

恢复了文件

是什么可能导致文件从其他用户的本地文件系统中删除?

请注意,有一个类似的问题询问发生这种情况时如何取消文件。因此发生这种情况,人们正在失去文件。

git pull将在另一个路径上删除曾经跟踪的文件。

请参阅为什么git rm-无法删除本地跟踪文件,而其他删除其他文件

最新更新