简体   繁体   中英

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? Please note that since the commit of 'xyz', a few more commits were pushed to this branch.

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:

# (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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