.
.
.
.
.
最近需要将不同的客户的代码分开管理,所以需要为这些代码分别创建分支。
目前版本库中分支结构如下:
[yuhuashi@local:Project]$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/masger
remotes/origin/master
其中 master 分支是客户 A 所使用的分支。
其它客户则以 masger 分支为基础版本创建。
大致需求的流程如下:
1.以 masger 分支作为基础为客户 B 创建分支 join。
2.将客户 A 的 master 分支重命名为 work。
修改后的分支应该如下所示:
$ git branch -a
* join
remotes/origin/HEAD -> origin/join
remotes/origin/work
remotes/origin/join
remotes/origin/masger
好了,叙述完了需求,那么就从头开始做起。
1.从远程仓库 clone 代码到本地,并创建本地仓库。
[yuhuashi@local:~]$ git clone ssh://user@192.168.4.9/~/proj/Project
Cloning into 'Project'...
user@192.168.4.9's password:
remote: Counting objects: 7981, done.
remote: Compressing objects:100% (5962/5962), done.
remote: Total7981 (delta 2504), reused 6801 (delta 1784)
Receiving objects:100% (7981/7981), 125.27 MiB | 25.29 MiB/s, done.
Resolving deltas:100% (2504/2504), done.
[yuhuashi@local:~]$ cd Project/[yuhuashi@local:Project]$ git branch-a*master
remotes/origin/HEAD -> origin/master
remotes/origin/masger
remotes/origin/master
[yuhuashi@local:Project]$
解释:通过 git branch -a 命令可以看到当前的分支结构。
2.创建一个空分支
[yuhuashi@local:Project]$ git checkout --orphan joinSwitched to a new branch'join'[yuhuashi@local:Project]$ gitrm -rf .rm '.gitignore'
rm 'Project.xcodeproj/project.pbxproj'
rm 'Project/Base.lproj/LaunchScreen.xib'
rm 'Project/Base.lproj/Main.storyboard'......
[yuhuashi@local:Project]$
[yuhuashi@local:Project]$ git branch -a
master
remotes/origin/HEAD -> origin/master
remotes/origin/masger
remotes/origin/master
[yuhuashi@local:Project]$
解释:git checkout 的时候指定 --orphan 参数可以创建一个不包含历史 log 的分支,如果使用 git branch join 会创建一个与当前分支一模一样的叫做 join 的分支,会带着 master 分支的 log。
分支创建好之后再使用 git rm -rf . 来删除当前分支下所有被跟踪的文件。
当然,使用 checkout 创建的这个空分支使用 git branch -a 命令是看不见的,必须 commit 一次才能看见。
但是直接在这个空分支中 commit 也是不可以的(如下所示),必须在这里做一些修改才能提交。
[yuhuashi@local:Project]$ git add .
[yuhuashi@local:Project]$ git status
# On branchjoin#
# Initial commit
#
nothing to commit (create/copy files and use "git add"to track)
[yuhuashi@local:Project]$ git commit-m "Initial commit"# On branchjoin#
# Initial commit
#
nothing to commit (create/copy files and use "git add"to track)
[yuhuashi@local:Project]$