Git 小抄

删除远程分支

# 删除远程分支 xxx
git push origin :xxx

统计提交者的 commit 数量

git shortlog -sn

删除某一次 commit

git revert --strategy resolve <commit>

git diff 中文乱码

在命令行下输入以下命令:

最后一条命令是因为 git log 默认使用 less 分页,所以需要 bash 对 less 命令进行 utf-8 编码 想长期生效的 话要改profile添加环境变量

$ git config --global core.quotepath false          # 显示 status 编码
$ git config --global gui.encoding utf-8            # 图形界面编码
$ git config --global i18n.commit.encoding utf-8    # 提交信息编码
$ git config --global i18n.logoutputencoding utf-8  # 输出 log 编码
$ export LESSCHARSET=utf-8

git更新 commit author

git filter-branch --env-filter '
    if [ "$GIT_AUTHOR_NAME" = "Old Name" ]; then \
        export GIT_AUTHOR_NAME="New Name" GIT_AUTHOR_EMAIL="[email protected]"; \
    fi
  '

Git tags

List tags

To list all tags, use the following command.

git tag

创建 Tags

Git uses two main types of tags: lightweight and annotated.

lightweight tag

git tag <tagname>  

annotated tag

To create an annotated tag in Git you can just run the following simple commands on your terminal.

$ git tag -a v2.1.0 -m "xxx feature is released in this tag."
$ git tag
v1.0.0
v2.0.0
v2.1.0

Push Tag

To push particular tag you can use below command:

$ git push origin v1.0.9

删除tag

$ git tag -d v1.0
Deleted tag 'v1.0' (was 808b598)

$ git push --delete origin v1.0
本文由 络壳 原创或整理,转载请注明出处