master分支删除文件_git 创建远程分支和删除 master 分支

这篇博客详细介绍了如何在Git中为不同客户创建分支,包括从master分支删除文件,创建远程分支,以及重命名master分支为work的过程。通过一系列git命令,如git checkout --orphan、git rm、git commit、git push等,实现了分支的管理和重命名。
摘要由CSDN通过智能技术生成

.

.

.

.

.

最近需要将不同的客户的代码分开管理,所以需要为这些代码分别创建分支。

目前版本库中分支结构如下:

[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]$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值