# 设置全局换行git config --global core.autocrlf input# 设置全局日志日期格式git config --global log.date iso8601# 设置当前库提交模板git config --local commit.template <file>
git filter-branch --tree-filter 'rm -f common/common-jar/pom.xml' HEAD
git filter-branch --tree-filter 'rm -rf common/common-jar' HEAD
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdingit reflog expire --expire=now --allgit gc --prune=now
git push origin --force --allgit push origin --force --tags
git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_EMAIL" = "huikai@test.com" ];thenGIT_AUTHOR_NAME="huikai";GIT_AUTHOR_EMAIL="huikai@itith.com";git commit-tree "$@";elsegit commit-tree "$@";fi' HEAD
git filter-branch --commit-filter 'if [ "$GIT_COMMITTER_EMAIL" = "huikai@test.com" ];thenGIT_COMMITTER_NAME="huikai";GIT_COMMITTER_EMAIL="huikai@itith.com";git commit-tree "$@";elsegit commit-tree "$@";fi' HEAD
git filter-branch --msg-filter 'sed -e "s/原字符串/新字符串/g"' HEAD
git filter-branch --index-filter \'git ls-files -s | sed "s-\t\"*-&子目录名称/-" |GIT_INDEX_FILE=$GIT_INDEX_FILE.new \git update-index --index-info &&if test -f "$GIT_INDEX_FILE.new"; then mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE; fi' HEAD
子目录名称如有中划线需要转义
git filter-branch --subdirectory-filter 子目录 HEAD
git commit -sSm
git commit -sS -m "提交说明"
git rebase -S 来源分支名
git tag -s 标签名称 -m '标签说明'
git config --global user.signingkey <keyid>
git config --local user.signingkey <keyid>
git config --global commit.gpgsign true
git config --global gpg.program <程序>
指定要使用哪个程序进行签名和验证。其命令行必须符合GPG标准。用于选择特定的GPG版本(例如,gpg2 vs gpg)或自定义程序
git tag -a 标签名称 9fceb0b
git push origin 标签名称
git push origin --tags
git log --author=<pattern>
git log --grep=<pattern>
git log --grep=<pattern> <filepath>
git diff hash1 hash1 --stat
git diff --name-status hash1 hash2
git diff hash1 hash2 --name-only | grep -v '<file>' | xargs git diff hash1 hash2 --
忽略空格变化git diff -b <file>
忽略所有空格git diff -w <file>
如要重新指定用户名和邮箱,需要建立映射文件(users.txt),格式:
huikai = huikai <huikai@itith.com>huikai = huikai2 <huikai2@itith.com>
git svn clone <svn路径> --authors-file=users.txt --no-metadata -T trunk <目录名>
git svn fetch
git svn rebase
git svn dcommit
git merge <分支名> --allow-unrelated-histories
原则: 确保要rebase的代码全部都是未提交远程仓库的代码,rebase前最好先将<来源分支>更新到最新
git rebase -S 来源分支
git rebase --onto 来源分支 起始分支 操作分支
git rebase 来源分支 操作分支
git pull --rebase
或git fetch + git rebase 远程分支
git update-index --assume-unchanged <文件路径>
git update-index --no-assume-unchanged <文件路径>
git ls-files -v 结果中以h开头的为忽略文件
或git ls-files -v | grep ^h
git reset <commit id>
使用git revert <commit id>来撤销某一次提交
如果想撤销多次提交可以多次调用撤销命令,如果不想看到多次提交的历史记录可以使用参数-n或者--no-commit在撤销时不自动提交,等把所有的撤销操作完以后使用git revert --continue统一提交
git revert -n <commit id>
git branch -m <原分支名> <新分支名>
git branch -d <分支名>
强制删除git branch -D <分支名>
git push <远程源> :<分支名>
git log --format='%aE' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done