git 从远程拉取一个文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12176307/
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-19 07:26:05  来源:igfitidea点击:

git pull one file from remote

gitgit-pull

提问by user429400

I've cloned a repository "Rep" and created my own local branch "Li". I've committed a file called "task.js" to the local "Li" branch and pushed it to the remote "Li" branch. Now I want to revert this action by:

我克隆了一个存储库“Rep”并创建了我自己的本地分支“Li”。我已将名为“task.js”的文件提交到本地“Li”分支并将其推送到远程“Li”分支。现在我想通过以下方式恢复此操作:

  1. pulling the original "task.js" from the remote "master" branch to the local "Li" branch
  2. push the reverted "task.js" from the local "Li" branch to the remote "Li" branch.
  1. 将原来的“task.js”从远程“master”分支拉到本地“Li”分支
  2. 将恢复的“task.js”从本地“Li”分支推送到远程“Li”分支。

I tried to read several "pull" tutorials but can't figure out a way to do this (maybe because I don't really understand the basics yet...)

我试图阅读几个“拉”教程,但无法找到一种方法来做到这一点(也许是因为我还不太了解基础知识......)

Thanks, Li

谢谢,李

回答by weynhamz

git reset HEAD~will revert the laster commit of the current branch, but since you have already pushed the branch Li to public, it is better to do a git checkout master task.jsand commit again in your branch Li.

git reset HEAD~将恢复当前分支的最后一次提交,但由于您已经将分支 Li 推送到公共,因此最好git checkout master task.js在您的分支 Li 中执行一次并再次提交。

回答by Mohanraj

You just simply revert a tom first commit using below command,

您只需使用以下命令简单地还原 tom 第一次提交,

git reset HEAD^1

git 重置 HEAD^1

Then then push the changes to remote branch.

然后将更改推送到远程分支。