附录1:常用git命令
1、查看分支列表
git命令详解
# 列出所有本地分支
git branch
# 列出所有远程分支
git branch -r
# 列出所有本地分支和远程分支
git branch -a
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (feature-resttemplate)
$ git branch
feature-eureka
* feature-resttemplate
master
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (feature-resttemplate)
$ git branch -r
origin/feature-eureka
origin/feature-resttemplate
origin/master
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (feature-resttemplate)
$ git branch -a
feature-eureka
* feature-resttemplate
master
remotes/origin/feature-eureka
remotes/origin/feature-resttemplate
remotes/origin/master
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (feature-resttemplate)
$
其中,分支前的*表示当前处在哪个分支
2、查看当前分支状态
git命令详解
# 查看状态
git status
# 查看状态 使输出信息更加简洁
git status –s
具体示例
存在未提交文件
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (feature-resttemplate)
$ git status
On branch feature-resttemplate
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.md
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (feature-resttemplate)
$ git status -s
M readme.md
无任何需要提交文件
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
$ git status
On branch feature-test
nothing to commit, working tree clean
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
$ git status -s
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
3、创建分支
git命令详解
# 创建分支
git branch <分支名>
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git branch feature-test
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
4、删除分支(本地)
git命令详解
# 删除分支(如果分支已经修改过,则不允许删除)
git branch -d <分支名>
# 强制删除分支
git branch -D <分支名>
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git branch -d feature-test
Deleted branch feature-test (was 89a11e6).
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git branch -d feature-test
error: The branch 'feature-test' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature-test'.
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git branch -D feature-test
Deleted branch feature-test (was 4546a15).
5、提交分支到远程仓库
git命令详解
# 提交分支至远程仓库
git push <仓库简称> <分支名称>
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
$ git push origin feature-test
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
remote: Create a pull request for 'feature-test' on Gitee by visiting:
remote: https://gitee.com/yanhan-git/micro-service-demom/pull/new/yanhan-git:feature-test...yanhan-git:master
To https://gitee.com/yanhan-git/micro-service-demom.git
* [new branch] feature-test -> feature-test
6、删除分支(远程)
git命令详解
# 删除远程仓库分支
git push <仓库简称> –d <分支名称>
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
$ git push origin -d feature-test
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yanhan-git/micro-service-demom.git
- [deleted] feature-test
7、合并分支(将指定分支合并到当前分支,可直接合并远程分支)
git命令详解
# 合并分支 将其他分支合并至当前工作区
git merge <分支名称>
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
$ git branch -a
* feature-test
master
remotes/origin/HEAD -> origin/master
remotes/origin/feature-eureka
remotes/origin/feature-resttemplate
remotes/origin/feature-test
remotes/origin/master
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
$ git merge remotes/origin/feature-resttemplate
Updating 89a11e6..4546a15
Fast-forward
assets/1661432091821.png | Bin 0 -> 13973 bytes
……中间省略大量记录……
assets/1661459606134.png | Bin 0 -> 15136 bytes
.../java/cn/yanhan/order/OrderApplication.java | 7 ++
.../java/cn/yanhan/order/mapper/OrderMapper.java | 3 +-
.../src/main/java/cn/yanhan/order/pojo/Order.java | 6 +-
.../src/main/java/cn/yanhan/order/pojo/User.java | 10 +++
.../java/cn/yanhan/order/service/OrderService.java | 18 ++++-
order-service/src/main/resources/application.yml | 6 +-
readme.md | 75 +++++++++++++++++++--
.../src/main/java/cn/yanhan/user/pojo/User.java | 2 +-
20 files changed, 116 insertions(+), 11 deletions(-)
create mode 100644 assets/1661432091821.png
……中间省略大量记录……
create mode 100644 assets/1661459606134.png
create mode 100644 order-service/src/main/java/cn/yanhan/order/pojo/User.java
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
$ git push origin -d feature-test
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yanhan-git/micro-service-demom.git
- [deleted] feature-test
8、查看标签列表
git命令详解
# 列出所有tag
git tag
# 查看tag详细信息
git show [tagName]
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (master)
$ git tag
0.0.0-initialize
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (master)
$ git show 0.0.0-initialize
tag 0.0.0-initialize
Tagger: YanHan <YanHan>
Date: Thu Aug 25 10:48:14 2022 +0800
初始化版本标签
commit 9c4b707304985d2e6a080b1776600fb32ea6a801 (tag: 0.0.0-initialize)
Author: YanHan <YanHan>
Date: Tue Aug 23 00:43:45 2022 +0800
项目初始化
:
tag 0.0.0-initialize
Tagger: YanHan <YanHan>
Date: Thu Aug 25 10:48:14 2022 +0800
初始化版本标签
commit 9c4b707304985d2e6a080b1776600fb32ea6a801 (tag: 0.0.0-initialize)
Author: YanHan <YanHan>
Date: Tue Aug 23 00:43:45 2022 +0800
项目初始化
9、新建tag标签
git命令详解
# 新建一个tag
git tag [tagName]
# 新建一个tag,并添加描述信息
git tag [tagName] -m [description]
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (master)
$ git tag 1.1.0-resttemplate -m "服务远程调用-通过RestTemplate实现http请求方式的远程调用"
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (master)
10、提交tag标签
git命令详解
# 提交指定tag
$ git push [仓库简称] [tagName]
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/cloud-demo (master)
$ git push origin 1.1.0-resttemplate
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 225 bytes | 225.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yanhan-git/micro-service-demom.git
* [new tag] 1.1.0-resttemplate -> 1.1.0-resttemplate
11、删除本地tag标签
git命令详解
# 删除本地tag
$ git tag -d [tag]
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git tag 0.0.1-test -m "测试用tag"
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git tag -d 0.0.1-test
Deleted tag '0.0.1-test' (was 0c61498)
12、删除远程tag标签 (注意 空格)
git命令详解
# 删除远程tag (注意 空格)
$ git push origin :refs/tags/[tag]
# 删除远程tag (注意 空格)
$ git push origin -d [tag]
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git push origin :refs/tags/0.0.1-test
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yanhan-git/micro-service-demom.git
- [deleted] 0.0.1-test
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git push origin -d 0.0.1-test
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yanhan-git/micro-service-demom.git
- [deleted] 0.0.1-test
13、新建一个分支,指向某个tag标签
git命令详解
# 新建一个分支,指向某个tag
$ git checkout -b [branchname] [tagname]
具体示例
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git tag
0.0.0-initialize
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git branch
* master
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (master)
$ git checkout -b feature-test 0.0.0-initialize
Switched to a new branch 'feature-test'
Administrator@Administrator MINGW64 /d/DevWorkSpaces/版本情况验证/micro-service-demom (feature-test)
根据tag标签创建分支,并切换到新建分支下