将我的回购分支与原始回购同步
Syncing my fork of repo with original repo
我看到很多关于这个的帖子,我知道一般的答案,从我的 fork 的本地 repo 执行这个:
git remote add upstream https://github.com/abcd/efgh.git
git fetch upstream
git merge upstream/master
(resolve merge conflicts)
git commit -m "my message"
git push
但我有一些超出一般情况的问题。
- 当我执行
git push
时,为什么我不必指定要推送到的遥控器?或者我呢?
- 此外,我如何从
upstream
获取特定的提交 ID,而不是我在 fetch upstream
时获得的最新提交?
git push
没有任何进一步的参数将使用分支的上游来确定推送到哪里。如果您在一个分支上,那么 git status
将向您显示该分支的当前上游(如果有)。
您可以 git branch --unset-upstream
或 git --set-upstream=newupstream/example
如果您想将当前签出的分支推送到特定位置,例如上游你可以做 git push upstream master
指定要获取的提交:例如git fetch upstream 61586219a7450af5a72f857db62d9a89ad9cc38f
可以使用 FETCH_HEAD
在 git 命令中访问获取的提交。例如。 git log FETCH_HEAD
.
注意:并非所有存储库都允许获取任意提交。例如。他们可能只允许获取命名分支和拉取请求 (github)。
我所做的是:
git remote add upstream https://github.com/abcd/efgh.git
git fetch upstream
git checkout 1q2w3e4r5t -b giveItABranchName
git checkout main
git merge giveItABranchName
(resolve merge conflicts)
git commit -m "my message"
git push
我看到很多关于这个的帖子,我知道一般的答案,从我的 fork 的本地 repo 执行这个:
git remote add upstream https://github.com/abcd/efgh.git
git fetch upstream
git merge upstream/master
(resolve merge conflicts)
git commit -m "my message"
git push
但我有一些超出一般情况的问题。
- 当我执行
git push
时,为什么我不必指定要推送到的遥控器?或者我呢? - 此外,我如何从
upstream
获取特定的提交 ID,而不是我在fetch upstream
时获得的最新提交?
git push
没有任何进一步的参数将使用分支的上游来确定推送到哪里。如果您在一个分支上,那么git status
将向您显示该分支的当前上游(如果有)。
您可以git branch --unset-upstream
或git --set-upstream=newupstream/example
如果您想将当前签出的分支推送到特定位置,例如上游你可以做git push upstream master
指定要获取的提交:例如
git fetch upstream 61586219a7450af5a72f857db62d9a89ad9cc38f
可以使用FETCH_HEAD
在 git 命令中访问获取的提交。例如。git log FETCH_HEAD
.
注意:并非所有存储库都允许获取任意提交。例如。他们可能只允许获取命名分支和拉取请求 (github)。
我所做的是:
git remote add upstream https://github.com/abcd/efgh.git
git fetch upstream
git checkout 1q2w3e4r5t -b giveItABranchName
git checkout main
git merge giveItABranchName
(resolve merge conflicts)
git commit -m "my message"
git push