简体   繁体   English

从本地机器上删除文件后,如何从 github 拉取以再次获取该文件?

[英]After deleting a file from my local machine, how do I pull from github to obtain that file again?

Here is a chronological summary of what happened.以下是按时间顺序对所发生的事情进行的总结。

  1. My local copy of a branch, let's call it featurebranch is fully up to date with the copy of this branch on github我的本地分支副本,我们称之为 featurebranch 与 github 上的此分支副本完全同步
  2. On my local machine, I delete a file called test.csv.在我的本地机器上,我删除了一个名为 test.csv 的文件。
  3. I call "git pull origin featurebranch" on my local machine, but the test.csv does not show up on my local machine我在本地机器上调用“git pull origin featurebranch”,但 test.csv 没有出现在我的本地机器上
  4. I call "git status" and output is "Changes not staged for commit: deleted test.csv"我称之为“git status”,output 是“未为提交暂存更改:已删除 test.csv”
  5. I call "git add test.csv"我叫“git add test.csv”
  6. I call "git status" and output is "Changes to be committed: deleted test.csv"我称之为“git status”,output 是“要提交的更改:已删除 test.csv”
  7. I call "git commit - m "delete test file""我称“git commit -m”删除测试文件“”
  8. I call "git pull origin featurebranch" and output is "Already up to date"我称“git pull origin featurebranch”和 output 是“已经是最新的”

It's not up to date though.虽然它不是最新的。 test.csv still exists on github but not on my local machine. test.csv 仍然存在于 github 但不在我的本地机器上。 How do I get this file back on my local machine?如何在我的本地机器上取回这个文件? I assume there is something about how git works that I do not realize.我认为 git 的工作原理有些我没有意识到。 Thank you for reading.感谢您的阅读。

git pull is used to "sync" your branch with the latest commits in the remote repository (GitHub). git pull用于将您的分支与远程存储库 (GitHub) 中的最新提交“同步”。 It is not used to sync files .用于同步文件

Since featurebranch was never updated in the remote with new commits that you don't have, git pull has nothing to do - there are no new commits to fetch and sync to.由于featurebranch从未使用您没有的新提交在远程进行更新,因此git pull无关 - 没有新的提交可以获取和同步。 Your commit is the most up-to-date version of that branch.您的提交是该分支的最新版本。

If you want your file back, you can either git reset <older_commit> the branch to some older commit that contained the branch.如果你想要你的文件,你可以git reset <older_commit>为包含该分支的一些较旧的提交。 Or you can git revert <the_commit_that_deleted_the_file> the commit that deleted that file.或者您可以git revert <the_commit_that_deleted_the_file>删除该文件的提交。 Or you can git checkout <some_other_commit> -- test.csv to selectively restore the file from <some_other_commit> that contains the file.或者您可以git checkout <some_other_commit> -- test.csv选择性地从包含该文件的<some_other_commit>中恢复该文件。 Or you can git checkout or git switch to some other branch/commit to change your working directory to a commit that actually had that file.或者您可以git checkoutgit switch到其他一些分支/提交,以将您的工作目录更改为实际具有该文件的提交。

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

相关问题 如何访问与本地计算机不同的服务器上存在的 hadoop 文件系统上的文件? - How do I access files on a hadoop file system present on a different server from my local machine? 如何从 github 获取文件到我的 python 代码中 - How do I get a file from github into my python code 如何将 .parquet 文件从本地计算机上传到 Azure Storage Data Lake Gen2? - How can I upload a .parquet file from my local machine to Azure Storage Data Lake Gen2? 如何从 python 中的文件路径中提取最后 3 个级别? - How do I pull last 3 levels from a file path in python? 如何使用 python 从 JSON 文件中提取对象? - How do I pull objects from a JSON file using python? 如何提取我的git用户邮件用户和密码以从本地存储库发送电子邮件? - how do I pull my git user mail user and password to send email from my local repository? 如何使用 github 从 kivy 创建一个 apk 文件 - How do I create an apk file from kivy with github 正确指定从本地开发机器进行git pull的路径 - Properly specifying path for git pull from my local development machine 如何仅使用file1中的索引从file2获取值(行)? - How do I obtain values(lines) from file2 using only indices in file1? 如何从google驱动器存储中的文件中获取创建日期? - How can I obtain the creation date from a file from my google drive storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM