简体   繁体   English

为什么 git pull 不能恢复已删除的文件?

[英]Why git pull doesnt' restore deleted files?

There're two remote repos on github: github 上有两个远程仓库:

repo_course : course instructor regularly release new assignment skeleton code; repo_course :课程导师定期发布新的作业骨架代码;

repo_me : my own with completed assignment code to grade; repo_me :我自己完成的作业代码来评分;

It works like that:它是这样工作的:

git clone <repo_me url> : create local working repo on my computer which is empty git clone <repo_me url> :在我的计算机上创建本地工作git clone <repo_me url> ,它是空的

git add remote skeleton <repo_course url>

git pull skeleton master : fetch skeleton code, complete it, and push to repo_me git pull skeleton master : 获取骨架代码,完成并push送到repo_me

My question is:我的问题是:

Suppose that I pulled skeleton.java and rename or delete it, then I git pull skeleton master again, it won't restore.假设我拉了skeleton.java并重命名或删除它,然后我再次git pull skeleton master ,它不会恢复。 Why is that?这是为什么? It seems pull will add the new skeleton files only once at the first pull since last time.这似乎pull将在第一只有一次添加新的框架文件pull自最后一次。 What's the benefits of its being designed like this?它被设计成这样有什么好处?

What should I do if I indeed need to restore my deleted files from repo_course ?如果我确实需要从repo_course恢复我删除的文件,我repo_course怎么repo_course

If you want your work replayed, instead of their work merged, try (with Git 2.9 or more):如果您希望重播您的工作,而不是合并他们的工作,请尝试(使用 Git 2.9 或更高版本):

git config --global pull.rebase true
git config --global rebase.autoStash true

Then a simple git pull will replay (rebase) your local commits (including your file rename) on top of what you are fetching.然后一个简单的 git pull 将在您获取的内容之上重放(rebase)您的本地提交(包括您的文件重命名)。

"Why git pull doesnt' restore deleted files? “为什么 git pull 不能恢复已删除的文件?

Because a merge would override local modification (like the file rename) with what is merged.因为合并会用合并的内容覆盖本地修改(如文件重命名)。
As opposed to rebase, which will rebase your own local work (like a file rename) on top of what is fetched.与 rebase 不同,它会将您自己的本地工作(如文件重命名)重新设置在获取的内容之上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM