你不想知道的git

Posted by Turingdo Studio on November 12, 2020

Git

对项目某些测试文件设置忽略

  1. 将文件修改忽略

git update-index --assume-unchanged [FILENAME]

  1. 取消文件忽略

git update-index --no-assume-unchanged [FILENAME]

# git 别名设置 
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.pk cherry-pick
git config --global alias.sh stash
git config --global alias.br branch
git config --global alias.unstage 'reset HEAD'  # 可以把暂存区的修改撤销掉(unstage),重新放回工作区
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.last 'log -3 --pretty=oneline --abbrev-commit' # 显示最近三次的提交历史
git config --global alias.pr 'pull --rebase' # git pull --rebase
# 输出全局设置信息
git config --global

# 设置git识别文件大小写
git config core.ignorecase false

git for-each-ref

git for-each-ref --count=3 --sort='-*authordate' \
           --format='From: %(*authorname) %(*authoremail)
           Subject: %(*subject)
           Date: %(*authordate)
           Ref: %(*refname)

           %(*body)
           ' 'refs/tags'

\
           --format='Subject: %(*subject)'

git config --global alias.mbr "for-each-ref --count=5 --sort=-committerdate refs/heads/ \ --format='%(refname:short) %(authorname) Subject: %(*subject)'"
git for-each-ref --sort=-committerdate refs/heads/ --format='%1B[0;31m %(refname:short)%1B[m   %(subject) %(color:green)%(refname:short)%(color:reset)'
git for-each-ref --no-merged dev --sort=-committerdate --count=5   refs/heads/ --format='%(color:green)%(refname:short)%(color:reset)   %(subject)'

项目常用的 彩色输出最常用的分支

git config --global alias.mbr "for-each-ref --no-merged dev --count=5 --sort=-committerdate refs/heads/  --format='%(color:green)%(refname:short)%(color:reset)   %(subject)'"

git config --global alias.mbr10 "for-each-ref --no-merged dev --count=10 --sort=-committerdate refs/heads/  --format='%(color:green)%(refname:short)%(color:reset)   %(subject)'"

git commit -m 与 git commit -am 的区别

git commit -am 'messages...' 仅会 已经追踪过且修改了的文件 起作用,第一次提交时,还需要 分步操作

git revert -no-commit 简写为 git revert -n [commitID] 可以理解为反退,撤销某次提交,但是在它之后的提交历史还会保留。

git reset –hard [commitID] 回退某一次提交,但是不保留在提交历史记录里面
git reset –soft [commitID] 回退commit信息,修改过的文件,会保留

Git–拉取远程分支,git pull,git rebase,git pull –rebase的区别

git pull

  相当于自动的 fetch 和 merge 操作,会试图自动将远程库合并入本地库,在有冲突时再要求手动合并。

git rebase

  可以确保生产分支commit是一个线性结构,方便rollback。其实生产也可以选择打tag来发布。

  注:通过rebase可以确保主分支commit history线性结构上每个commit点都是相对独立完整的功能单元。除了美感,这样做也有助于团队间的分工协作,比随便merge效果好。

git pull --rebase(推荐用这个)

把本地 repo. 从上次 pull 之后的变更暂存 恢复到上次 pull 时的状态 合并远端的变更到本地 最后再合并刚刚暂存下來的本地变更 git fetch

  只是将远程的文件拉下来,不会与本地的分支进行合并