简体   繁体   English

如何从远程分支中提取特定的提交?

[英]How to pull a specific commit from a remote branch?

How do I pull a specific commit (eg: with an id of 'xyz') to my local machine from a remote branch? 如何从远程分支将特定的提交(例如,ID为'xyz')拉到本地计算机? Please note that since the commit of 'xyz', a few more commits were pushed to this branch. 请注意,自提交“ xyz”以来,又有一些提交被推送到该分支。

Also, I am already on this remote branch and not the master. 另外,我已经在此远程分支上,而不是主服务器上。

The repo that I have only includes the master and the branch I want to pull from. 我拥有的存储库仅包括要从中提取的主服务器和分支。

I'm aware there are many posts regarding this issue however none of them seem to focus specifically to my issue. 我知道有很多关于此问题的帖子,但是似乎没有一个专门针对我的问题。

Assuming your branch name is <branchname> , you could do something like: 假设您的分支名称为<branchname> ,则可以执行以下操作:

# (Optionally) Save your work to a 'temp' branch, in case you want to come back to it:
git checkout -b temp
git add -A .
git commit -m "WIP"

# Get back to your branch, and reset it to 'xyz':
git checkout <branchname>
git fetch origin
git reset --hard xyz

At this point, your branch is now at 'xyz' as per the remote, and you can start afresh from there. 此时,您的分支现在按照远程位于“ xyz”,您可以从那里重新开始。

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

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