git 工具使用记录

about git

Posted by cslqm on November 25, 2019

git 工具使用记录

记录用到的 git 命令,总是忘记,所以必须记一下啦。

获取远程tag

1
2
git tag  # 查看tag
git fetch origin tag <tagname>  # 下载 origin 的 tag

tag 创建

1
git tag <tagname> <commit>  # 在某个commit 上打tag

tag 删除

1
2
git tag -d <tagname>  # 删除本地 tag
git push origin :refs/tags/<tagname>    # 本地tag删除了,再执行该句,删除线上tag

tag 创建分支

1
git branch <new-branch-name> <tag-name>

取消提交到本地的 commit

1
git reset --mixed <commit>  # 保留变动代码

取消提交到远端的 commit

基本思路就是本地 reset 后,强制提交本地分支替换掉远端分支

1
2
3
4
git reset --mixed <commit> 
...
git push origin <branch_name> -f

查看当前用户等配置信息

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
git config --global --list  # 查看 global

usage: git config [options]

Config file location
    --global              use global config file
    --system              use system config file
    -f, --file <FILE>     use given config file

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 adds a new variable: name value
    --unset               removes a variable: name [value-regex]
    --unset-all           removes all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            opens an editor
    --get-color <slot>    find the color configured: [default]
    --get-colorbool <slot>
                          find the color setting: [stdout-is-tty]

Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)

Other
    -z, --null            terminate values with NUL byte

git 修改用户名和email

1
2
3
4
5
git config --global user.name "myname"
git config --global user.email  "test@gmail.com"

# 团队项目配置,每次新创建一个项目,需要执行下
git config --local user.name 'myname' && git config --local user.email 'test@gmail.com'