如何从远程分支挑选? [英] How to cherry-pick from a remote branch?

查看:124
本文介绍了如何从远程分支挑选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在挑选樱桃时遇到了麻烦。在我的本地机器上,我目前在我的主分支上。我想挑选另一个名为斑马的分支。 斑马分支是一个远程分支。



so git status:

 #分支主
没有提交(工作目录干净)

好吧,现在我尝试挑选提交I想要:

  git cherry-pick xyz 
致命错误对象xyz

其中xyz是我感兴趣的提交的签名,发生在分支斑马上。

所以第一个明显的问题是,为什么不能找到我参考的提交?我真的不明白这是如何工作的,坦率地说。 git是否在我的工作目录中存储类似于本地提交数据库的所有其他分支?在执行cherry-pick命令时,是否会去查找本地数据库以查找我正在谈论的提交?



由于zebra是远程分支,我以为我本地没有数据。所以我换了分支:

  git checkout zebra 
转换到分支'zebra'

所以现在在我的本地机器上,我可以看到目录中的文件正确反映了zerbra的状态。我切换回主,尝试再次选择(希望提交数据现在可用),但有一些问题。



我对于什么是最基本的误解

解决方案


由于zebra是一个远程分支,我想我本地没有数据


你是对的,你没有正确的数据,但试图以错误的方式解决它。要从远程源本地收集数据,您需要使用 git fetch 。当你做了 git checkout zebra 时,你切换到了最后一次获取分支的状态。首先从远程获取:

 #仅获取一个远程
git fetch< remote>
#或从所有遥控器中获取
git fetch --all
#确保你回到你想要挑选的分支上
git cherry-pick xyz


I'm having trouble performing a cherry-pick. On my local machine, I'm currently on my "master" branch. I want to cherry-pick in a commit from another branch, named "zebra". The "zebra" branch is a remote branch.

so git status:

# On branch master
nothing to commit (working directory clean)

ok, now I try to cherry-pick the commit I want:

git cherry-pick xyz
fatal: bad object xyz

where "xyz" is the signature of the commit I'm interested in, that happened on branch "zebra".

So the first obvious question is, why can't git find the commit I'm referencing? I don't really understand how this is working in the first place to be honest. Does git store something like a database of commits locally in my working directory, for all other branches? When executing the cherry-pick command, does it go and search that local database to find the commit I'm talking about?

Since "zebra" is a remote branch, I was thinking I don't have its data locally. So I switched branches:

git checkout zebra
Switched to branch 'zebra'

so now here on my local machine, I can see that the files in the directory reflect zerbra's state correctly. I switch back to master, try to cherry-pick again (hoping the commit data is available now), but some problem.

I've got a fundamental misunderstanding of what's going on here, any help would be great.

解决方案

Since "zebra" is a remote branch, I was thinking I don't have its data locally.

You are correct that you don't have the right data, but tried to resolve it in the wrong way. To collect data locally from a remote source, you need to use git fetch. When you did git checkout zebra you switched to whatever the state of that branch was the last time you fetched. So fetch from the remote first:

# fetch just the one remote
git fetch <remote>
# or fetch from all remotes
git fetch --all
# make sure you're back on the branch you want to cherry-pick to
git cherry-pick xyz

这篇关于如何从远程分支挑选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆