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

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

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


当前回答

你可以在一行中完成,如下所示。希望你在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]

其他回答

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

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

# 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

对于这种情况,必须为一些本地化验证“精心挑选”提交。 对于相同的存储库签出,也可以是本地提交(即尚未推送到服务器)。

E.g.

Repo1类似于repo2 repo1的分支b1 - HEAD在本地进行了2次提交(包括commit_x)。 Repo2有分支bb1 -需要挑选commit_x。

为此,

$ CD repo2

Repo2 $ git获取<path_to_repo1>

Repo2 $ git cherry-pick <commit_x>

在上面的例子中,commit_x现在是可识别的并被提取(通过fetch的帮助)。

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

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