从其他存储库中提取提交

编程入门 行业动态 更新时间:2024-10-26 10:38:07
本文介绍了从其他存储库中提取提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

使用

git fetch github/cvandermeer/wisemonkeys.git f70bcfd75a498ed9159b6e5313e306166fc3df62

投掷以下错误:

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

git remote -v 给我以下内容,

原始github/alucardu/appsynth.git(获取)来源github/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 给我以下内容[...]

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

git remote add alice github/cvandermeer/wisemonkeys.git

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

然后运行

git取爱丽丝

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

git name-rev f70bcfd75a498ed9159b6e5313e306166fc3df62

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

git show f70bcfd75a498ed9159b6e5313e306166fc3df62

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

  • git fetch 和 git remote 手册页
  • 相关问题:我该如何区分我的回购和不是起源的远程回购?

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 github/cvandermeer/wisemonkeys.git f70bcfd75a498ed9159b6e5313e306166fc3df62

throws the following error:

error: no such remote ref f70bcfd75a498ed9159b6e5313e306166fc3df62

git remote -v gives me the following,

origin github/alucardu/appsynth.git (fetch) origin github/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 github/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
  • git fetch and git remote man pages
  • related question: How can I diff between my repo and a remote repo that's not origin?

更多推荐

从其他存储库中提取提交

本文发布于:2023-11-23 21:13:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622880.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:库中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!