0%

git 分支常用常用操作

  • 查看所有分支:git branch -a
  • 查看当前使用的分支:git branch
  • 切换分支:git checkout [branchName]

查看分支

先将远程代码下载至本地,范例如下:

1
2
3
4
5
6
7
8
wankun@SH-WYZCY-XYFD MINGW64 /d/svn/Loan/branches/KUN-Console_Git
$ git clone http://10.138.61.72/abc/loan/console/Cn.XXX.AssistTask.git
Cloning into 'Cn.XXX.AssistTask'...
remote: Counting objects: 136, done.
remote: Compressing objects: 100% (82/82), done.
remote: Total 136 (delta 70), reused 97 (delta 47)
Receiving objects: 100% (136/136), 3.97 MiB | 22.96 MiB/s, done.
Resolving deltas: 100% (70/70), done.

查看分支:

1
2
3
4
5
6
7
wankun@SH-WYZCY-XYFD MINGW64 /d/svn/Loan/branches/KUN-Console_Git/Cn.XXX.AssistTask (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/develop
remotes/origin/develop_abc-IR-0028
remotes/origin/master

切换分支

前面查看分支可知本地只有【master】分支,而远程分支有:

  • remotes/origin/HEAD -> origin/master
  • remotes/origin/develop
  • remotes/origin/develop_abc-IR-0028
  • remotes/origin/master

现将本地分支切换到【develop_abc-IR-0028】:

1
2
3
4
wankun@SH-WYZCY-XYFD MINGW64 /d/svn/Loan/branches/KUN-Console_Git/Cn.XXX.AssistTask (master)
$ git checkout develop_abc-IR-0028
Switched to a new branch 'develop_abc-IR-0028'
Branch 'develop_abc-IR-0028' set up to track remote branch 'develop_abc-IR-0028' from 'origin'.

再次查看分支:

1
2
3
4
5
6
7
8
9
10
11
12
13
wankun@SH-WYZCY-XYFD MINGW64 /d/svn/Loan/branches/KUN-Console_Git/Cn.XXX.AssistTask (develop_abc-IR-0028)
$ git branch -a
* develop_abc-IR-0028
master
remotes/origin/HEAD -> origin/master
remotes/origin/develop
remotes/origin/develop_abc-IR-0028
remotes/origin/master

wankun@SH-WYZCY-XYFD MINGW64 /d/svn/Loan/branches/KUN-Console_Git/Cn.XXX.AssistTask (develop_abc-IR-0028)
$ git branch
* develop_abc-IR-0028
master

如果远程新增或删除了分支,需要先使用命令 git pull 先垃取,在查看,如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
wankun@SH-WYZCY-XYFD MINGW64 /d/svn/Loan/branches/PreLoan_Develop_VBS-IR-0035 (develop_VBS-IR-0)
$ git pull
remote: Counting objects: 586, done.
remote: Compressing objects: 100% (202/202), done.
remote: Total 586 (delta 399), reused 541 (delta 384)
Receiving objects: 100% (586/586), 669.83 KiB | 1.76 MiB/s, done.
Resolving deltas: 100% (399/399), done.
From http://10.138.61.72/vbs/service-group/web-site/PreLoan
a79e2e9..fcf21c0 develop -> origin/develop
* [new branch] develop_CR1188 -> origin/develop_CR1188
* [new branch] develop_CR1245 -> origin/develop_CR1245
* [new branch] develop_CR1247 -> origin/develop_CR1247
3b08624..25ea3cb develop_REQ467 -> origin/develop_REQ467
b422b49..eeb5dce master -> origin/master
Already up to date.

将一个分支同步到另一个分支

如将分支【develop-abc-IR-0035】的修改同步到分支【develop_abc-IR-0035】,先将分支切换到目标分支【develop_abc-IR-0035】:

1
2
3
$ git checkout develop_abc-IR-0035
Switched to branch 'develop_abc-IR-0035'
Your branch is up to date with 'origin/develop_abc-IR-0035'.

然后使用命令 git merge develop-abc-IR-0035,执行后会提示【hint:Waiting for your editor to close the file…】,然后会打开一个文件等待你关闭,被关闭后会继续执行。

范例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
wankun@SH-WYZCY-XYFD MINGW64 /d/svn/Loan/branches/PreLoan_Develop_abc-IR-0035 (develop_abc-IR-0035)
$ git merge develop-abc-IR-0035
Merge made by the 'recursive' strategy.
Cn.XXX.abc.Sys.API/Permission/PermisionAPI.cs | 78 ++++
Cn.XXX.abc.Sys.BLL/Permission/PermissionBLL.cs | 65 +++
Cn.XXX.abc.Sys.DAL/Permission/PermissionDal.cs | 320 ++++++++++++++
.../Cn.XXX.abc.Sys.Entities.csproj | 1 +
.../Permission/PermissionEntity.cs | 27 ++
ShareLib/Cn.XXX.AMS.WebService.dll | Bin 0 -> 12288 bytes
ShareLib/Cn.XXX.Common.Utility.dll | Bin 10240 -> 10240 bytes
ShareLib/Cn.XXX.Common.dll | Bin 777728 -> 828928 bytes
Sys/Cn.XXX.abc.Sys.csproj | 16 +
.../CustomerServiceNumber.aspx | 2 +-
Sys/EmployeeManage/EmployeeAdd.aspx | 3 +-
Sys/Product/ProductFeeRules.aspx | 4 +-
Sys/Product/ProductRules.aspx | 4 +-
Sys/UserManage/PermissionAdd.aspx | 184 ++++++++
Sys/UserManage/PermissionAdd.aspx.cs | 466 +++++++++++++++++++++
Sys/UserManage/PermissionAdd.aspx.designer.cs | 267 ++++++++++++
Sys/UserManage/PermissionManage.aspx | 129 ++++++
Sys/UserManage/PermissionManage.aspx.cs | 312 ++++++++++++++
Sys/UserManage/PermissionManage.aspx.designer.cs | 123 ++++++
Sys/Web.config | 6 +-
Sys/WorkLocIpMainten/WorkLocationList.aspx | 2 +-
21 files changed, 2000 insertions(+), 9 deletions(-)
create mode 100644 Cn.XXX.abc.Sys.Entities/Permission/PermissionEntity.cs
create mode 100644 ShareLib/Cn.XXX.AMS.WebService.dll
create mode 100644 Sys/UserManage/PermissionAdd.aspx
create mode 100644 Sys/UserManage/PermissionAdd.aspx.cs
create mode 100644 Sys/UserManage/PermissionAdd.aspx.designer.cs
create mode 100644 Sys/UserManage/PermissionManage.aspx
create mode 100644 Sys/UserManage/PermissionManage.aspx.cs
create mode 100644 Sys/UserManage/PermissionManage.aspx.designer.cs

提交信息为【Merge branch ‘develop-abc-IR-0035’ into develop_abc-IR-0035】。

您的支持是我最大的动力!