从其他存储库中提取提交 [英] Pull a commit from a different repository

查看:86
本文介绍了从其他存储库中提取提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经克隆了一个项目供我处理,但是一个朋友对原始项目进行了更改。我想将所做的更改从提交中提取到我的项目中。



使用

  git fetch https://github.com/cvandermeer/wisemonkeys.git f70bcfd75a498ed9159b6e5313e306166fc3df62 

投掷以下错误:


错误:没有这样的远程引用f70bcfd75a498ed9159b6e5313e306166fc3df62


git remote -v 给我以下内容,

 原始https://github.com/alucardu/appsynth.git(获取)
来源https://github.com/alucardu/appsynth.git(推送)

是否不可能从其他项目中提取提交?

解决方案

(为方便起见,在下面将您的朋友称为爱丽丝。)


您获取引用(分支或标签),而不是提交



我想将所做的更改从提交中提取到我的项目中。


是否不可能从其他项目中提取提交?


严格来说,您不提取提交;您获取引用(分支或标签)。如果您对Alice的回购中存在的特定提交感兴趣,而对您的不感兴趣,则需要从Alice的回购中获取其祖先包含有问题的提交的引用。


使用有效的 git fetch 语法



使用[...]会引发以下错误[... ]


您正在使用的命令,

  git fetch< ; remote-url> < commit> 

不是有效的 git fetch 语法,因此会出现错误越来越。您要使用的语法是

  git fetch< repository> 

其中< repository> 是远程的,即昵称根据该信息,您的本地仓库可以了解Alice的仓库。您可能需要更具体,还可以添加 refspec

编辑:如torek在他的评论,您也可以使用裸露的URL,而无需在本地存储库中配置远程服务器,但是可能不是这样您想要在这里做。


首先添加爱丽丝的回购作为远程



git remote -v 给我以下内容[...]


<$的输出c $ c> git remote -v 表示您尚未将Alice的存储库添加为本地存储库的 remote 。您需要先执行以下操作:

  git remote add alice https://github.com/cvandermeer/wisemonkeys.git 


获取并查找有关利益承诺的更多信息


然后运行

  git取爱丽丝

取回您所穿的一切还没有来自爱丽丝的仓库。然后可以运行

  git name-rev f70bcfd75a498ed9159b6e5313e306166fc3df62 

标识可从中访问提交的引用,并且

  git show f70bcfd75a498ed9159b6e5313e306166fc3df62 

打印有关提交的信息并决定如何处理(樱桃选择它,将其所在的分支合并到您的本地分支之一,等等)。 / p>

其他资源



I've cloned a project for me to work on, but a friend made a change on the original project. I would like to pull the changes from that commit into my project.

Using

git fetch https://github.com/cvandermeer/wisemonkeys.git f70bcfd75a498ed9159b6e5313e306166fc3df62

throws the following error:

error: no such remote ref f70bcfd75a498ed9159b6e5313e306166fc3df62

git remote -v gives me the following,

origin  https://github.com/alucardu/appsynth.git (fetch)
origin  https://github.com/alucardu/appsynth.git (push)

Is it not possible to pull a commit from a different project?

解决方案

(For convenience, let's call your friend "Alice" in the following.)

You fetch references (branches or tags), not commits

I would like to pull the changes from that commit into my project.

Is it not possible to pull a commit from a different project?

Strictly speaking, you don't fetch commits; you fetch references (branches or tags). If you're interested in a particular commit that exists in Alice's repo but not in yours, you'll need to fetch a reference whose ancestry contains the commit in question from Alice's repo.

Use a valid git fetch syntax

Using [...] throws the following error [...]

The command you're using,

git fetch <remote-url> <commit>

is not a valid git fetch syntax, hence the error you're getting. The syntax you want to use is

git fetch <repository> 

where <repository> is a remote, i.e. a nickname under which your local repo knows Alice's repo. You may want to be more specific and also add a refspec at the end of this command.

Edit: As pointed out by torek in his comment, you can also use a naked URL, without configuring the remote in your local repository, but that's probably not what you want to do, here.

Add Alice's repo as a remote first

git remote -v gives me the following [...]

The output of git remote -v indicates that you haven't added Alice's repo as a remote of your local repository yet. You need to to that before you can fetch from it:

git remote add alice https://github.com/cvandermeer/wisemonkeys.git

Fetch and find out more about the commit of interest

Then run

git fetch alice

to fetch everything you don't already have from Alice's repo. You can then run

git name-rev f70bcfd75a498ed9159b6e5313e306166fc3df62  

to identify a reference from which the commit is accessible, and

git show f70bcfd75a498ed9159b6e5313e306166fc3df62

to print information about the commit and decide what to do with it (cherry-pick it, merge the branch it's on into one of your local branches, etc.).

Additional resources

这篇关于从其他存储库中提取提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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