我正在使用一个git存储库,需要从另一个git存储库提交,该存储库对第一个一无所知。

通常我会在reflog中使用HEAD@{x}进行筛选,但因为这个.git不知道这个reflog条目(不同的物理目录),我如何才能筛选它,或者我可以吗?

我使用git-svn。我的第一个分支使用Subversion repo中继的git-svn,下一个分支在Subversion分支上使用git-svn。


当前回答

下面是添加远程、获取分支和选择提交的步骤

# Cloning our fork
$ git clone git@github.com:ifad/rest-client.git

# Adding (as "endel") the repo from we want to cherry-pick
$ git remote add endel git://github.com/endel/rest-client.git

# Fetch their branches
$ git fetch endel

# List their commits
$ git log endel/master

# Cherry-pick the commit we need
$ git cherry-pick 97fedac

来源:https://coderwall.com/p/sgpksw

其他回答

您需要将另一个存储库添加为远程存储库,然后获取其更改。从那里您可以看到提交,您可以选择它。

像这样:

git remote add other https://example.link/repository.git
git fetch other

现在您已经有了所有信息,可以简单地进行git优选。

完成后,如果你不再需要它,你可能想要再次移除它

git remote remove other

更多关于使用遥控器工作的信息,请访问:https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes

是的。获取存储库,然后从远程分支中进行选择。

如果您希望为给定文件挑选多个提交,直到完成给定提交,那么可以使用以下方法。

# Directory from which to cherry-pick
GIT_DIR=...
# Pick changes only for this file
FILE_PATH=...
# Apply changes from this commit
FIST_COMMIT=master
# Apply changes until you reach this commit
LAST_COMMIT=...

for sha in $(git --git-dir=$GIT_DIR log --reverse --topo-order --format=%H $LAST_COMMIT_SHA..master -- $FILE_PATH ) ; do 
  git --git-dir=$GIT_DIR  format-patch -k -1 --stdout $sha -- $FILE_PATH | 
    git am -3 -k
done

你可以在一行中完成,如下所示。希望你在git存储库中,需要精心挑选的更改,并且你已经签出了正确的分支。

git fetch ssh://git@stash.mycompany.com:7999/repo_to_get_it_from.git branchToPickFrom && git cherry-pick 02a197e9533
# 

git获取[分支URL][分支的cherry-pick from] && git cherry-pick[提交ID]

参见如何使用Git创建和应用补丁。(从你问题的措辞来看,我假设这个其他的存储库是用于完全不同的代码库的。如果它是相同代码库的存储库,您应该按照@CharlesB的建议将其添加为远程存储库。即使它是用于另一个代码库,我猜您仍然可以将其作为远程添加,但您可能不想将整个分支添加到存储库中…)