Git 处理tag和branch的命令

最近想给GitHub 上的项目设置tag,可是使用GitHub Desktop,找了一圈都没找到快速设置Tag 的地方,最后只能通过终端命令来添加了。
想要查看Git 的命令,可以使用

git --help

可是大致看一下git的命令:

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Forward-port local commits to the updated upstream head
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

然后使用 git help -agit help -g 可以查看git 的一些子命令和一些概念性的东西。

使用 git help <command>git help <concept> 可以查看某个命令的参数 和描述等详细信息。

要对某个Git 工程做处理,我们首先要先进入该工程的根目录。
可以使用 cd 工程路径 来进入某个工程目录。
然后可以使用 ls -a 或者 ls -al 查看工程目录下是否有隐藏的 .git 文件。
例如我的操作:

bogon:HLBluetoothDemo harvey$ ls -al
total 32
drwxr-xr-x   7 harvey  staff   238 11 18 17:41 .
drwxr-xr-x  63 harvey  staff  2142 11  1 11:03 ..
-rw-r--r--@  1 harvey  staff  6148  9 28 15:53 .DS_Store
drwxr-xr-x  16 harvey  staff   544 11 18 17:41 .git
drwxr-xr-x  23 harvey  staff   782 11 18 17:41 HLBluetoothDemo
drwxr-xr-x   5 harvey  staff   170 11 18 17:41 HLBluetoothDemo.xcodeproj
-rw-r--r--   1 harvey  staff  5066 11 18 17:41 README.md

Commit 操作

//查看所有提交记录
git log

// 查看简写的提交记录
git log --oneline

Tag 操作

我们可以对某一个稳定的版本设置一个Tag,这样在以后回头来看,也更方便和直接。

查看Tag 命令

// 查看本地的所有Tag
git tag
// 查看某一系列tag
git tag -l v1.*

创建Tag 命令

git tag -a v1.0 -m "对Tag的描述信息"

我们也可以对以前的某次commit 设置tag。
具体的做法是,首先执行 git log --oneline ,找到这次提交的唯一id。
例如:

bogon:HLBluetoothDemo harvey$ git log --oneline
2b04b38 利用iOS 9后的系统API获取特性可写入的最大长度来分割发送。
1468bbe Update README.md
fba0db7 断开连接时,将connectedperpwheral 置为nil
ee76062 Update README.md
576e179 Update README.md

上面的 描述信息前的值,就是id。

然后执行 git tag -a v1.1 2b04b38 -m "Tag的描述信息"

我们可以在本地添加多个tag 后,执行以下 git tag 查看一下本地的tag。

提交本地的Tag 到远程服务器的命令

git push origin --tags

然后,我们就可以去github 上看自己的工程里的tags 了。

删除本地的tag 命令

git tag -d v1.0

上面这个命令只能删除本地的tag,如果这个tag 已经提交到远程服务器之后,上面的命令并不能删除远程服务器上的tag。
要删除远程服务器上的tag,可以使用如下的命令:

git push origin --delete tag v1.0

branch 操作

查看branch 的命令

git branch -a

在终端里,远程的branch会显示为红色,如下图所示:

这里写图片描述

删除远程branch 的命令

git push origin --delete <branchName>

目前branch 就用到这么多,更详细的,使用git help branch 查看吧。
以后再补充了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值