目录
多人协作一(多人同一分支)
开发者一(Linux)
开发者二(Windous)
master合并
远端上的合并
本地上的合并
总结
多人协作一(多人多分支)
开发者一(Linux)
开发者二(Windous)
master合并
合并function-2
合并function-1
远程分支删除后,本地 git branch -a 依然能看到的解决办法
此处在 windows 环境下,再 clone 同⼀个项目仓库,来模拟协作开发的另⼀名开发人
员。我们在 windows 环境下,执行开辟一个文件夹。
使用Shift + 鼠标右键
此处为了简单就可以采取 HTTPS 方式进行克隆,与 Linux 一摸一样的方式即可。
之前有所提到 master 分支是一个稳定的分支,作为开发者不要在 master 分支上做直接的修改。所以在这里我们需要创建其他的分支,这个其他分支是在本地创建,还是远程创建是都可以的。
目标:
远程 master 分支下的 file.txt 文件新增代码 "aaaaaa" 、"bbbbbb" 。
实现:
由一个开发人员添加一行 "aaaaaa" ,另一名开发人员添加一行 "bbbbbb" 。
条件:
在一个分支下协作完成。
此处采用远程创建dev分支。
创建一个名为 dev 的分支。
此时我们需要明确的知道,远程仓库就有了两个分支:master 与 dev 分支。对应的一位开发者有一个根据远程仓库克隆出来的本地仓库,而此时本地仓库中有一个本地的 master 分支。其实现在本地还有一个分支,对应的远程的 master 分支:origin/master 分支。
可以使用 git branch -r 命令进行查看远程分支, git branch 命令是用于查看的是本地仓库的分支。
[qcr@ecs-205826 remote---project]$ git branch -r
origin/HEAD -> origin/master
origin/master
远程是有一个 HEAD 指针的,其是与我们本地仓库所讲的 HEAD 指针作用是一样的。创建成功的远程分支是可以通过 Git 拉取到本地来,以实现完成本地开发工作。
[qcr@ecs-205826 remote---project]$ git pull
From gitee.com:chuanru/remote---project
* [new branch] dev -> origin/dev
Already up-to-date.
[qcr@ecs-205826 remote---project]$ git branch -r
origin/HEAD -> origin/master
origin/dev
origin/master
补充:
命令 git branch -a 是既打印远程的也打印本地的。[qcr@ecs-205826 remote---project]$ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/dev remotes/origin/master
#:直接使用 git pull 就可以拉下来的原因。
之前有所提到,不管是 pull 操作,还是 push 操作,都是针对于分支的操作。之前我们针对于远程仓库的 master 分支,与本地仓库的 master 分支使用 push 操作:
想要 push ,就必须让两个分支之间建立连接。采取格式为:
git push <远程主机名> <本地分⽀名>:<远程分⽀名>
# 如果本地分⽀名与远程分⽀名相同,则可以省略冒号:
git push <远程主机名> <本地分⽀名>
这个时候其实是不需要建立连接的,而是想要简写的时候才需要建立连接,有了这个连接 Git 才会知道是哪个分支到哪个分支。所以可以理解为:连接的意义,指明 "方向" 。而 pull 与 push 同理。
所以在这里,直接使用了一个 git pull 操作,而并没有去指定后面的内容,而远程仓库的 master 与本地仓库的 master 是克隆的时候自动建立连接。所以可以不用指明,直接对于双方的 master 生效。
此时本地没有的 dev 分支,所以我们需要创建一个 dev 分支。
[qcr@ecs-205826 remote---project]$ git checkout -b dev origin/dev
Branch dev set up to track remote branch dev from origin.
Switched to a new branch 'dev'
[qcr@ecs-205826 remote---project]$ git branch -a
* dev
master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
[qcr@ecs-205826 remote---project]$ git branch -vv
* dev e532e80 [origin/dev] 创建.gitignore
master e532e80 [origin/master] 创建.gitignore
此时对 file.txt 文件就可以进行操作了。
[qcr@ecs-205826 remote---project]$ vim file.txt
[qcr@ecs-205826 remote---project]$ cat file.txt
hello Git
hello world
aaaaaa
然后便可以进行提交,并 push 到远程。
[qcr@ecs-205826 remote---project]$ git add .
[qcr@ecs-205826 remote---project]$ git commit -m "修改文件: 新增一行aaaaaa"
[dev 0303c49] 修改文件: 新增一行aaaaaa
1 file changed, 2 insertions(+), 1 deletion(-)
[qcr@ecs-205826 remote---project]$ git push
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 309 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To [email protected]:chuanru/remote---project.git
e532e80..0303c49 dev -> dev
此处采用本地以普通的方式创建 dev 分支,并不直接表明本地分支和远程分支的连接情况。
PS C:\Git\remote---project> git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
PS C:\Git\remote---project> git checkout -b dev
Switched to a new branch 'dev'
PS C:\Git\remote---project> git branch -vv
* dev e532e80 创建.gitignore
master e532e80 [origin/master] 创建.gitignore
此时发现我们本地仓库创建的 dev 分支,确实没有任何与远程的连接。此时就可以验证我们之前所讲的连接是指明 "方向" 。也就是对于 pull 与 push 无需准确的表明方向,有连接不用表明,无连接需表明。
PS C:\Git\remote---project> git pull
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/ dev
此处提示:当前分支 dev 没有连接的分支,要推送当前分支并将远程设置为连接。此处使用: git branch --set-upstream-to=origin/
PS C:\Git\remote---project> git branch -vv
* dev e532e80 [origin/dev: behind 1] 创建.gitignore
master e532e80 [origin/master] 创建.gitignore
此时我们发现,开发者二的仓库中只有。
PS C:\Git\remote---project> cat file.txt
hello Git
hello world
是由于开发者二的 dev 分支是来源于 master 分支的,所以没有文件的变化也是合乎常理的,于是开发者二开始他的工作。
PS C:\Git\remote---project> git branch
* dev
master
PS C:\Git\remote---project> cat file.txt
hello Git
hello world
bbbbbb
然后开发者二开始进行提交和 push 操作。
PS C:\Git\remote---project> git add .
PS C:\Git\remote---project> git commit -m "修改文件:新增一行bbbbbb"
[dev 073c54c] 修改文件:新增一行bbbbbb
1 file changed, 2 insertions(+), 1 deletion(-)
PS C:\Git\remote---project> git push
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
To https://gitee.com/chuanru/remote---project.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/chuanru/remote---project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
PS C:\Git\remote---project> git pull
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
PS C:\Git\remote---project> cat file.txt
hello Git
hello world
<<<<<<< HEAD
bbbbbb
=======
aaaaaa
>>>>>>> 0303c49e6d41a9afd09d8b901e8603fa02c2b36a
PS C:\Git\remote---project> cat file.txt
hello Git
hello world
aaaaaa
bbbbbb
PS C:\Git\remote---project> git add .
PS C:\Git\remote---project> git commit -m "merge dev"
[dev 8be002b] merge dev
PS C:\Git\remote---project> git push
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 578 bytes | 578.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/chuanru/remote---project.git
0303c49..8be002b dev -> dev
PR(Pull Request)。
对于本地上的合并,情况是多样化的,以最复杂的情况为目标。
开发人员一
此时开发者一的本地dev为。
[qcr@ecs-205826 remote---project]$ git branch
* dev
master
[qcr@ecs-205826 remote---project]$ cat file.txt
hello Git
hello world
aaaaaa
切换至 dev 分支,pull ⼀下,保证本地的 dev 是最新内容(将相关的"aaaaaa" "bbbbbb"都拉下来)。
[qcr@ecs-205826 remote---project]$ git pull
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
From gitee.com:chuanru/remote---project
0303c49..8be002b dev -> origin/dev
Updating 0303c49..8be002b
Fast-forward
file.txt | 1 +
1 file changed, 1 insertion(+)
[qcr@ecs-205826 remote---project]$ cat file.txt
hello Git
hello world
aaaaaa
bbbbbb
接下来就为了保证 master 的最新性,合并前这么做是⼀个好习惯。
[qcr@ecs-205826 remote---project]$ git checkout master
Switched to branch 'master'
[qcr@ecs-205826 remote---project]$ git pull
Already up-to-date.
[qcr@ecs-205826 remote---project]$ git checkout dev
Switched to branch 'dev'
[qcr@ecs-205826 remote---project]$ git merge master
Already up-to-date.
切换至 master 分支,合并 dev 分支。
[qcr@ecs-205826 remote---project]$ git checkout master
Switched to branch 'master'
[qcr@ecs-205826 remote---project]$ git merge dev
Updating e532e80..8be002b
Fast-forward
file.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[qcr@ecs-205826 remote---project]$ cat file.txt
hello Git
hello world
aaaaaa
bbbbbb
随后进行 push 操作即可。
[qcr@ecs-205826 remote---project]$ git push
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To [email protected]:chuanru/remote---project.git
e532e80..8be002b master -> master
于是此时 dev 的任务完成了,dev 就没有任何用处了,也就可以删除了。
所以:同一分支下多人协作的过程下是有一些问题的。多人在同一个分支下进行开发,基本上是必然有冲突的,而解决冲突是非常麻烦的事情 —— 其实这个工作模式是不常见的。
目标:
远程 master 分支下的新增 function1文件、function2文件。
实现:
由一个开发人员新增 function1文件,另一名开发人员新增 function2文件。
条件:
在不同分支下协作完成,各自让某一个功能私有一个分支。
此处采用本地创建分支,然后再将本地分支推向远程仓库中。
推荐选择第一个,创建远程分支,因为远程分支如基于master的新建,是能够保证远程的master分支是最新、最全、最稳定的代码,所以远程基于master创建出来的分支,也是最新、最全、最稳定的代码。
如果通过本地的master创建的分支,由于本地的master分支不能保证是最新、最全、最稳定的代码。是需要使用pull操作来保证的,比起远端是需要更多的、更麻烦的步骤的。
[qcr@ecs-205826 remote---project]$ git branch -a
dev
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
[qcr@ecs-205826 remote---project]$ git checkout -b function-1
Switched to a new branch 'function-1'
这一次后面是没有办法跟上远程的分支的,因为对于远程来说,都没有 function-1 分支,于是便没有办法让远程分支和本地分支去建立连接。
[qcr@ecs-205826 remote---project]$ vim function1
[qcr@ecs-205826 remote---project]$ cat function1
I am coding ……
Done
[qcr@ecs-205826 remote---project]$ git add .
[qcr@ecs-205826 remote---project]$ git commit -m "新增一个function1文件"
[function-1 740ad8d] 新增一个function1文件
1 file changed, 2 insertions(+)
create mode 100644 function1
之后就该进行 push 操作了,就可以将本地分支 push 到远程仓库中。
[qcr@ecs-205826 remote---project]$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Everything up-to-date
直接进行 push 是不可以的,因为本地并未和远程建立连接。是还有一种: git push origin 分支 的方式,直接将本地分支推送向远端。
[qcr@ecs-205826 remote---project]$ git push origin function-1
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 317 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
remote: Create a pull request for 'function-1' on Gitee by visiting:
remote: https://gitee.com/chuanru/remote---project/pull/new/chuanru:function-1...chuanru:master
To [email protected]:chuanru/remote---project.git
* [new branch] function-1 -> function-1
首先需要保证本地仓库master分支的代码为最新、最全、最稳定的。
PS C:\Git\remote---project> git branch
dev
* master
PS C:\Git\remote---project> cat .\file.txt
hello Git
hello world
PS C:\Git\remote---project> git pull
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 297 bytes | 49.00 KiB/s, done.
From https://gitee.com/chuanru/remote---project
e532e80..8be002b master -> origin/master
* [new branch] function-1 -> origin/function-1
Updating e532e80..8be002b
Fast-forward
file.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
PS C:\Git\remote---project> cat .\file.txt
hello Git
hello world
aaaaaa
bbbbbb
随后就可以创建一个最新、最全、最稳定的本地分支。
PS C:\Git\remote---project> git checkout -b function-2
Switched to a new branch 'function2'
PS C:\Git\remote---project> git add .
PS C:\Git\remote---project> git commit -m "新增文件function2"
[function-2 4c84244] 新增文件function2
1 file changed, 2 insertions(+)
create mode 100644 function2.txt
PS C:\Git\remote---project> git push origin function-2
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 310 bytes | 310.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
remote: Create a pull request for 'function-2' on Gitee by visiting:
remote: https://gitee.com/chuanru/remote---project/pull/new/chuanru:function-2...chuanru:master
To https://gitee.com/chuanru/remote---project.git
* [new branch] function-2 -> function-2
可以发现执行到现在,根本就不用解决任何的冲突,原因就是分支是各自私有一份的,它们是独立的。正常情况下,二者就可以在自己的分支上进行专业的开发了。
[qcr@ecs-205826 remote---project]$ git pull
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From gitee.com:chuanru/remote---project
* [new branch] function-2 -> origin/function-2
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/ function-1
融汇贯通的理解:
对于 pull 操作:
- 用于拉取分支中的内容 - 是必须需要建立连接的。
- 用于拉取远程仓库中的内容 - 是可以不用让分支建立连接的,因为和分支没有关系,拉取的是仓库。
[qcr@ecs-205826 remote---project]$ git branch -a
dev
* function-1
master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/function-1
remotes/origin/function-2
remotes/origin/master
[qcr@ecs-205826 remote---project]$ git checkout -b function-2 origin/function-2
Branch function-2 set up to track remote branch function-2 from origin.
Switched to a new branch 'function-2'
[qcr@ecs-205826 remote---project]$ vim function2.txt
[qcr@ecs-205826 remote---project]$ cat function2.txt
I am coding……
aaaaaaaaaaaaaaaaaa
Done
[qcr@ecs-205826 remote---project]$ git add .
[qcr@ecs-205826 remote---project]$ git commit -m "修改文件function2"
[function-2 f2a379e] 修改文件function2
1 file changed, 2 insertions(+), 1 deletion(-)
[qcr@ecs-205826 remote---project]$ git push
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 296 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To [email protected]:chuanru/remote---project.git
4c84244..f2a379e function-2 -> function-2
查看远程状态,推送成功了:
这时,我们的同事已经修养的差不多,可以继续进行自己的开发工作,那么他首先要获取到我们帮他开发的内容,然后接着你的代码继续开发。或者你已经帮他开发完了,那他也需要在自己的电脑上看看我们帮他写的代码。
PS C:\Git\remote---project> cat .\function2.txt
I am coding鈥︹€?
Done
PS C:\Git\remote---project> git pull
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 276 bytes | 34.00 KiB/s, done.
From https://gitee.com/chuanru/remote---project
4c84244..f2a379e function-2 -> origin/function-2
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/ function-2
PS C:\Git\remote---project> cat .\function2.txt
I am coding鈥︹€?
Done
PS C:\Git\remote---project> git branch --set-upstream-to=origin/function-2 function-2
Branch 'function-2' set up to track remote branch 'function-2' from 'origin'.
PS C:\Git\remote---project> git pull
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
Updating 4c84244..f2a379e
Fast-forward
function2.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
PS C:\Git\remote---project> cat .\function2.txt
I am coding鈥︹€?
aaaaaaaaaaaaaaaaaa
Done
切换至 master ,进行 pull 保证本地 master 是最新内容。
PS C:\Git\remote---project> git branch
function-2
* master
PS C:\Git\remote---project> git pull
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
Already up to date.
切换至 function-2 分支,合并 master 分支。
PS C:\Git\remote---project> git checkout function-2
Switched to branch 'function-2'
Your branch is up to date with 'origin/function-2'.
PS C:\Git\remote---project> git merge master
Already up to date.
切换至 master 分支,合并 function-2 分支。
PS C:\Git\remote---project> git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
PS C:\Git\remote---project> git merge function-2
Updating 8be002b..f2a379e
Fast-forward
function2.txt | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 function2.txt
将 master 分支推送至远端。
PS C:\Git\remote---project> git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
PS C:\Git\remote---project> git push
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
info: detecting host provider for 'https://gitee.com/'...
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/chuanru/remote---project.git
8be002b..f2a379e master -> master
[qcr@ecs-205826 remote---project]$ git branch
function-1
function-2
* master
[qcr@ecs-205826 remote---project]$ git pull
From gitee.com:chuanru/remote---project
8be002b..f2a379e master -> origin/master
Updating 8be002b..f2a379e
Fast-forward
function2.txt | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 function2.txt
[qcr@ecs-205826 remote---project]$ git function-1
git: 'function-1' is not a git command. See 'git --help'.
[qcr@ecs-205826 remote---project]$ git checkout function-1
Switched to branch 'function-1'
[qcr@ecs-205826 remote---project]$ git merge master
Merge made by the 'recursive' strategy.
function2.txt | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 function2.txt
[qcr@ecs-205826 remote---project]$ ls
a.so b.so file.txt function1 function2.txt README.en.md README.md
[qcr@ecs-205826 remote---project]$ git push
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 310 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To [email protected]:chuanru/remote---project.git
740ad8d..e75c59c function-1 -> function-1
[qcr@ecs-205826 remote---project]$ git checkout master
Switched to branch 'master'
[qcr@ecs-205826 remote---project]$ git merge function-1
Updating f2a379e..e75c59c
Fast-forward
function1 | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 function1
[qcr@ecs-205826 remote---project]$ ls
a.so b.so file.txt function1 function2.txt README.en.md README.md
[qcr@ecs-205826 remote---project]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
[qcr@ecs-205826 remote---project]$ git push
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To [email protected]:chuanru/remote---project.git
f2a379e..e75c59c master -> master
[qcr@ecs-205826 remote---project]$ git status
# On branch master
nothing to commit, working directory clean
此时远程仓库的状态。
当前我们已经删除了远程的几个分支,使用 git branch -a 命令可以查看所有本地分支和远程分支,但发现很多在远程仓库已经删除的分支在本地依然可以看到。之前的一系列操作后。
[qcr@ecs-205826 remote---project]$ git branch -a
function-1
function-2
* master
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/function-1
remotes/origin/function-2
remotes/origin/master
[qcr@ecs-205826 remote---project]$ git branch show origin
Branch show set up to track remote branch master from origin.
[qcr@ecs-205826 remote---project]$ git remote show origin
* remote origin
Fetch URL: [email protected]:chuanru/remote---project.git
Push URL: [email protected]:chuanru/remote---project.git
HEAD branch: master
Remote branches:
master tracked
refs/remotes/origin/dev stale (use 'git remote prune' to remove)
refs/remotes/origin/function-1 stale (use 'git remote prune' to remove)
refs/remotes/origin/function-2 stale (use 'git remote prune' to remove)
Local branches configured for 'git pull':
function-2 merges with remote function-2
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
[qcr@ecs-205826 remote---project]$ git remote prune origin
Pruning origin
URL: [email protected]:chuanru/remote---project.git
* [pruned] origin/dev
* [pruned] origin/function-1
* [pruned] origin/function-2
[qcr@ecs-205826 remote---project]$ git branch -a
function-1
function-2
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
补充:
对于已经使用完的本地分支,本地仓库就可以进行删除了。[qcr@ecs-205826 remote---project]$ git branch -d function-1 Deleted branch function-1 (was e75c59c). [qcr@ecs-205826 remote---project]$ git branch -d function-2 Deleted branch function-2 (was f2a379e). [qcr@ecs-205826 remote---project]$ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master