简体   繁体   English

为什么git pull恢复我从工作目录中删除的文件?

[英]Why doesn't git pull restore files I've deleted from my working directory?

I Have a problem with git My problem is the following, when I make a pull: 我有一个git的问题我的问题如下,当我拉一下:

git pull origin example

Until there Perfect!!, Then I make a 直到那里完美!!,然后我做一个

rm -Rf rootdirectory

Then 然后

git commit -am "Delete files"

and Then again I make a pull because I need this files 然后我再次拉,因为我需要这个文件

git pull origin example

but it isn't get again the rootdirectory 但它不再是根目录

This is a message: 这是一条消息:

Already up-to-date.

How I can do for get the files with git pull again? 我怎样才能再次使用git pull获取文件?

The reason git pull does not change anything is that you are not pulling data from the remote repository, you are pulling changes . git pull没有改变任何东西的原因是你没有从远程存储库中提取数据 ,你正在拉动变化 And there are no changes for git to pull! 并没有改变git拉!

Git is not a data store. Git不是数据存储。 It's a version control system 这是一个版本控制系统

However, if you want to checkout the previous state you can easily do that: 但是,如果你想出以前的状态,你可以很容易地做到这一点:

git checkout HEAD~1

This means you are resetting your working copy to the previous state before the latest commit. 这意味着您将工作副本重置为最新提交之前的先前状态。

If however, you would like to completely remove the commit that deleted the files, you can do that as well: 但是,如果您想完全删除删除文件的提交,您也可以这样做:

git reset --hard HEAD~1

Am I right in thinking that you're used to Subversion, where if you deleted the files, and then did a svn update , the files would get repopulated? 我是否认为你已经习惯了Subversion,如果你删除了文件,然后进行了svn update ,那么这些文件会被重新填充? Me, too. 我也是。

In git, you have to do git checkout to bring files out of the repo. 在git中,你必须进行git checkout才能将文件从repo中删除。 You can also use git reset --hard to update the files, but doing so will wipe out any changes in the working directory. 您也可以使用git reset --hard来更新文件,但这样做会消除工作目录中的任何更改。

This is the way git works. 这就是git的工作方式。 After pulling origin/example and committing your change ("Delete files") your local repo is ahead of origin/master by that 1 commit: 在提取origin/example并提交更改(“删除文件”)后,您的本地仓库将超过该提交的origin/master

A---B---C  origin/master
         \
          D  master

Where D is your Delete files commit. 其中D是您的Delete files提交。 Another git pull gives you Already up-to-date because there are no new commits on origin/master that could be pulled into your local repo. 另一个git pull给你Already up-to-date因为没有新的提交origin/master可以被拉入你的本地仓库。

To "get the files again", you can either undo you last commit: 要“再次获取文件”,您可以撤消上次提交:

git checkout HEAD~1

Or you can reset your local repository to match the remote repository: 或者,您可以重置本地存储库以匹配远程存储库:

git reset --hard origin/master

Go to the directory where the files are deleted, make sure you are on the branch you want and type "git checkout ." 转到删除文件的目录,确保您在所需的分支上并键入“git checkout”。 this will bring back the files you deleted on your current branch. 这将带回您在当前分支上删除的文件。

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

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