我正在使用一个git存储库,需要从另一个git存储库提交,该存储库对第一个一无所知。
通常我会在reflog中使用HEAD@{x}进行筛选,但因为这个.git不知道这个reflog条目(不同的物理目录),我如何才能筛选它,或者我可以吗?
我使用git-svn。我的第一个分支使用Subversion repo中继的git-svn,下一个分支在Subversion分支上使用git-svn。
我正在使用一个git存储库,需要从另一个git存储库提交,该存储库对第一个一无所知。
通常我会在reflog中使用HEAD@{x}进行筛选,但因为这个.git不知道这个reflog条目(不同的物理目录),我如何才能筛选它,或者我可以吗?
我使用git-svn。我的第一个分支使用Subversion repo中继的git-svn,下一个分支在Subversion分支上使用git-svn。
当前回答
如果您希望为给定文件挑选多个提交,直到完成给定提交,那么可以使用以下方法。
# 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
其他回答
下面是添加远程、获取分支和选择提交的步骤
# 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存储库中,需要精心挑选的更改,并且你已经签出了正确的分支。
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 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
是的。获取存储库,然后从远程分支中进行选择。
你可以这样做,但是需要两个步骤。方法如下:
git fetch <remote-git-url> <branch> && git cherry-pick FETCH_HEAD
将<remote-git-url>替换为您想从中选择的存储库的url或路径。
将<branch>替换为您想要从远程存储库中挑选的分支或标记名称。
你可以用分支中的git SHA替换FETCH_HEAD。
更新:根据@pkalinow的反馈进行了修改。