如何添加分支作为分支?
How to add fork as branch?
Caffe的fork很多,比如MS有自己的Caffefork.
我想做的是将一些分支与原始 Caffe 的主分支进行比较。
我知道使用 git 我可以 compare 2 branches,但我的问题是如何添加分支作为分支。
我试过了this:
git clone https://github.com/BVLC/caffe.git
Cloning into 'caffe'...
remote: Counting objects: 32907, done.
remote: Total 32907 (delta 0), reused 0 (delta 0), pack-reused 32907
Receiving objects: 100% (32907/32907), 43.55 MiB | 571 KiB/s, done.
Resolving deltas: 100% (21962/21962), done.
cd caffe_BVLC/
git branch -l
* master
git remote add caffe_MS https://github.com/Microsoft/caffe.git
git remote -v
caffe_MS https://github.com/Microsoft/caffe.git (fetch)
caffe_MS https://github.com/Microsoft/caffe.git (push)
origin https://github.com/BVLC/caffe.git (fetch)
origin https://github.com/BVLC/caffe.git (push)
git fetch caffe_MS
remote: Counting objects: 409, done.
remote: Total 409 (delta 177), reused 177 (delta 177), pack-reused 232
Receiving objects: 100% (409/409), 136.98 KiB, done.
Resolving deltas: 100% (279/279), completed with 89 local objects.
From https://github.com/Microsoft/caffe
* [new branch] bvlc_merge_2016_03_04 -> caffe_MS/bvlc_merge_2016_03_04
* [new branch] bvlc_windows_matlab -> caffe_MS/bvlc_windows_matlab
* [new branch] master -> caffe_MS/master
From https://github.com/Microsoft/caffe
* [new tag] 0.1w -> 0.1w
git branch -l
* master
git checkout --track caffe_MS/MS
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'caffe_MS/MS' which can not be resolved as commit?
我做错了什么,我应该指定哪个分支名称?
更新:
@hek2mgl
的解决方案结果
git clone https://github.com/BVLC/caffe.git
Cloning into 'caffe'...
remote: Counting objects: 33290, done.
remote: Total 33290 (delta 0), reused 0 (delta 0), pack-reused 33290
Receiving objects: 100% (33290/33290), 43.93 MiB | 484 KiB/s, done.
Resolving deltas: 100% (22252/22252), done.
cd caffe
git remote add caffe_MS https://github.com/Microsoft/caffe.git
git fetch caffe_MS master
remote: Counting objects: 379, done.
remote: Total 379 (delta 111), reused 111 (delta 111), pack-reused 268
Receiving objects: 100% (379/379), 130.06 KiB, done.
Resolving deltas: 100% (246/246), completed with 62 local objects.
From https://github.com/Microsoft/caffe
* branch master -> FETCH_HEAD
git diff caffe_MS/master
fatal: ambiguous argument 'caffe_MS/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
更新
您使用的是 git 的旧版本。更新至 git >= 2
以使以下命令生效。我正在使用 2.4.10
.
以下命令可以解决问题:
# Clone repo
git clone https://github.com/BVLC/caffe.git
cd caffe
# Add remote
git remote add caffe_MS https://github.com/Microsoft/caffe.git
# Fetch remote master from fork
git fetch caffe_MS master
# Compare to local master
# We are currently working in the local master that's why it can be omitted
git diff caffe_MS/master
I know that using git I can compare 2 branches, but my question is how to add fork as branch.
当你说你知道如何比较两个分支时,我想你的意思是你真的知道如何比较本地分支,并且你缺少的是如何比较远程分支。
首先,您可以看到远程分支列表:
git branch -r
并且您可以通过在远程名称前加上前缀来比较远程分支,例如:
git diff origin/master caffe_MS/master
至于最后一个错误,不清楚您要用 git checkout --track caffe_MS/MS
做什么。你的解释是关于比较分支和添加分支,你从来没有提到跟踪。如果你想从一个分支中检出一个分支,你可以使用与检出原始分支时相同的语法:
git checkout -b caffe_MS_master caffe_MS/master
Caffe的fork很多,比如MS有自己的Caffefork.
我想做的是将一些分支与原始 Caffe 的主分支进行比较。
我知道使用 git 我可以 compare 2 branches,但我的问题是如何添加分支作为分支。
我试过了this:
git clone https://github.com/BVLC/caffe.git
Cloning into 'caffe'...
remote: Counting objects: 32907, done.
remote: Total 32907 (delta 0), reused 0 (delta 0), pack-reused 32907
Receiving objects: 100% (32907/32907), 43.55 MiB | 571 KiB/s, done.
Resolving deltas: 100% (21962/21962), done.
cd caffe_BVLC/
git branch -l
* master
git remote add caffe_MS https://github.com/Microsoft/caffe.git
git remote -v
caffe_MS https://github.com/Microsoft/caffe.git (fetch)
caffe_MS https://github.com/Microsoft/caffe.git (push)
origin https://github.com/BVLC/caffe.git (fetch)
origin https://github.com/BVLC/caffe.git (push)
git fetch caffe_MS
remote: Counting objects: 409, done.
remote: Total 409 (delta 177), reused 177 (delta 177), pack-reused 232
Receiving objects: 100% (409/409), 136.98 KiB, done.
Resolving deltas: 100% (279/279), completed with 89 local objects.
From https://github.com/Microsoft/caffe
* [new branch] bvlc_merge_2016_03_04 -> caffe_MS/bvlc_merge_2016_03_04
* [new branch] bvlc_windows_matlab -> caffe_MS/bvlc_windows_matlab
* [new branch] master -> caffe_MS/master
From https://github.com/Microsoft/caffe
* [new tag] 0.1w -> 0.1w
git branch -l
* master
git checkout --track caffe_MS/MS
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'caffe_MS/MS' which can not be resolved as commit?
我做错了什么,我应该指定哪个分支名称?
更新: @hek2mgl
的解决方案结果git clone https://github.com/BVLC/caffe.git
Cloning into 'caffe'...
remote: Counting objects: 33290, done.
remote: Total 33290 (delta 0), reused 0 (delta 0), pack-reused 33290
Receiving objects: 100% (33290/33290), 43.93 MiB | 484 KiB/s, done.
Resolving deltas: 100% (22252/22252), done.
cd caffe
git remote add caffe_MS https://github.com/Microsoft/caffe.git
git fetch caffe_MS master
remote: Counting objects: 379, done.
remote: Total 379 (delta 111), reused 111 (delta 111), pack-reused 268
Receiving objects: 100% (379/379), 130.06 KiB, done.
Resolving deltas: 100% (246/246), completed with 62 local objects.
From https://github.com/Microsoft/caffe
* branch master -> FETCH_HEAD
git diff caffe_MS/master
fatal: ambiguous argument 'caffe_MS/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
更新
您使用的是 git 的旧版本。更新至 git >= 2
以使以下命令生效。我正在使用 2.4.10
.
以下命令可以解决问题:
# Clone repo
git clone https://github.com/BVLC/caffe.git
cd caffe
# Add remote
git remote add caffe_MS https://github.com/Microsoft/caffe.git
# Fetch remote master from fork
git fetch caffe_MS master
# Compare to local master
# We are currently working in the local master that's why it can be omitted
git diff caffe_MS/master
I know that using git I can compare 2 branches, but my question is how to add fork as branch.
当你说你知道如何比较两个分支时,我想你的意思是你真的知道如何比较本地分支,并且你缺少的是如何比较远程分支。
首先,您可以看到远程分支列表:
git branch -r
并且您可以通过在远程名称前加上前缀来比较远程分支,例如:
git diff origin/master caffe_MS/master
至于最后一个错误,不清楚您要用 git checkout --track caffe_MS/MS
做什么。你的解释是关于比较分支和添加分支,你从来没有提到跟踪。如果你想从一个分支中检出一个分支,你可以使用与检出原始分支时相同的语法:
git checkout -b caffe_MS_master caffe_MS/master