为什么 git pull 不带回我删除的目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9305326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:00:04  来源:igfitidea点击:

Why doesn't git pull bring back directories that I've deleted?

git

提问by Marty

I've just started learning how to use gittoday, progressing well.

git今天刚刚开始学习如何使用,进展顺利。

As an experiment, I used pushto upload two directories (containing two files each) and two files in the root directory. This worked fine.

作为一个实验,我曾经push上传两个目录(每个包含两个文件)和根目录下的两个文件。这工作得很好。

I then deleted one of the two directories that I have locally (but not on git). When I use git statusit seems to be aware of this:

然后我删除了我在本地拥有的两个目录之一(但不在 git 上)。当我使用git status它时似乎意识到这一点:

deleted: test/Testfile.as
deleted: test/Testile2.as

deleted: test/Testfile.as
deleted: test/Testile2.as

But when I use git pullto get my files back, they don't seem to return to my local folder. I've also tried git fetch.

但是当我git pull用来取回我的文件时,它们似乎没有返回到我的本地文件夹。我也试过了git fetch

The only way I seem to be able to get everything back is git clone, but that doesn't seem logical as I need to delete my master directory locally and then clone it back again (or alternatively specify a new location for the cloned files).

我似乎能够恢复所有内容的唯一方法是git clone,但这似乎不合逻辑,因为我需要在本地删除我的主目录,然后再次将其克隆回来(或者为克隆文件指定一个新位置)。

What is the appropriate way to retrieve files and folders from github that have been deleted locally?

从 github 中检索已在本地删除的文件和文件夹的适当方法是什么?

回答by manojlds

git pulljust merges the fetched commits in your working directory and will not restore your deleted directory ( but might warn you about conflicts.)

git pull只是将获取的提交合并到您的工作目录中,并且不会恢复您删除的目录(但可能会警告您发生冲突。)

If you have deleted the folders in your working directory, you have to do:

如果您删除了工作目录中的文件夹,则必须执行以下操作:

git checkout -- test

to get it back.

把它拿回来。

Or you can do git reset --hardto completely bring your working directory to HEAD state.

或者您可以git reset --hard将您的工作目录完全置于 HEAD 状态。

回答by checkorbored

you want to return your repository to the previous working version. this is a job for git-reset.

您想将存储库返回到以前的工作版本。这是 git-reset 的工作。

git reset --hard

be sure to read through this useful explanation of git-reset

一定要通读这个有用的 git-reset 解释

you could also check out those files if you wanted to:

如果您想,您还可以查看这些文件:

git checkout -- test/

回答by Tim Hoolihan

git pull will merge in changes. think of it like a file you've modified. a git pull doesn't replace the contents of the file with the remotes copy if you've modified it. even if there is a conflicting change, then it just warns you of a fastforward.

git pull 将合并更改。把它想象成一个你修改过的文件。如果您修改了文件,则 git pull 不会用远程副本替换文件的内容。即使存在相互冲突的更改,它也会警告您快进。

If you have your repository in a state where the delete is the only uncommitted change, and you want to undo it, then do a git reset head --hard

如果您的存储库处于删除是唯一未提交更改的状态,并且您想撤消它,请执行以下操作 git reset head --hard

Or, if you have other changes you want to leave in place, do git checkout -- test

或者,如果您想保留其他更改,请执行 git checkout -- test

回答by rashok

Apart from git pulland git checkout, git revertalso will be helpful to get back the deleted files

除了git pulland之外git checkoutgit revert也将有助于找回已删除的文件

回答by Ramaprasad reddy

git reset --hard <commit hash>means HEAD will be pointing at a particular commit and whatever commits you've made after that commit hash won't be available. The reason for this is because you are pointing HEAD to separate commit HASH. If you push forcibly then you will lose all commits.

git reset --hard <commit hash>意味着 HEAD 将指向特定的提交,并且您在该提交哈希之后所做的任何提交都将不可用。这样做的原因是因为您将 HEAD 指向单独的提交哈希。如果您强行推送,那么您将丢失所有提交。

Note: Be carefull when using git reset --hardcommand in git.

注意:git reset --hard在 git 中使用命令时要小心。