目录

git 常用命令

git log --since=midnight --author="$(git config user.name)" --pretty=tformat: --numstat  | awk '{add += $1; del += $2; loc += $1 - $2} END {print "新增:", add, "删除:", del, "净增:", loc}'
git clone -b v5.12 git@gitee.com:xxx/xxx.git
 git ck -b feature-tszz_iter1.0 origin/feature-tszz_iter1.0
git log --graph --pretty=oneline --abbrev-commit
git remote add origin git@github.com:michaelliao/learngit.git
git push -u origin master
git diff readme.txt
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.lg "log --graph --pretty=oneline --abbrev-commit"
git config --global alias.st "status"
git config --global alias.ck "checkout"
git config --global alias.br "branch"
  • 命令git tag <tagname>用于新建一个标签,默认为HEAD,也可以指定一个commit id;
  • 命令git tag -a <tagname> -m "blablabla..."可以指定标签信息;
  • 命令git tag可以查看所有标签。
  • 命令git push origin <tagname>可以推送一个本地标签;
  • 命令git push origin --tags可以推送全部未推送过的本地标签;
  • 命令git tag -d <tagname>可以删除一个本地标签;
  • 命令git push origin :refs/tags/<tagname>可以删除一个远程标签。
git log --since="6am"
# 暂存包含新增的文件(即未跟踪)并注释 msg
git stash save -u "msg"

# 应用指定暂存
git stash apply stash@{1}

fatal: refusing to merge unrelated histories

解决方案: 在你操作命令后面加–allow-unrelated-histories eg: git merge master –allow-unrelated-histories git pull origin master –allow-unrelated-histories

解决方案:

  1. git rm -r --cached 要忽略的文件 (如: git rm -r --cached build/*, 如修改列表中的内容全部是不需要的, 那么你可以使用最最简单的命令搞定git rm -r --cached .)
  2. git add .
  3. git commit -m " commet for commit ....."
  4. git push

默认对大小写不敏感 文件名相同 造成 Changes not staged for commit 错误

解决方案:

git config --global core.ignorecase false

win上会提示CRLF will be replaced by LF

解决方案: https://stackmirror.com/questions/5834014

git config --global core.autocrlf input
git commit --amend
git config core.quotepath false  --global
git push origin -d 
git remote prune origin
git checkout fileName
// or
git checkout .
# 删除文件
rm filename

# 删除新增的文件,如果文件已经已经 git add 到暂存区,并不会删除! 
git clean -xdf

# 同上,但是还会处理文件夹
git clean -xdff
git reset HEAD <fileName>
git add fileName 
git commit -amend -m '说明'
git reset [--hard|soft|mixed|merge|keep] [commit|HEAD]
# 查看文件版本
git log <filename>
git checkout <commitID> <fileName>
git revert HEAD // 是反做了目标版本,产生一个新的commits

git reset --hard HEAD^ // 会删除目标版本后的版本
# 先查看此次合并的详情
git show --no-patch f4d6542f44 

# out 如下,合并的 commit 会有两个 parent : 52xxx 和 81xx 
commit f4d6542f44efabfa7d38995e17216859d534f57a 
Merge: 520d7c2503 81c5344dc8
	... 

# git需要你明确告知 以哪一条 parent 作为主线(正确历史)?
# 可以通过 show 命令来查看提交内容, -m 1, 代表以 52xxx 为主线
git revert -m 1 f4d6542f44

git push

# 如果冲突了,也别慌,解决完
git add .
git revert --continue

git checkout b

# 查看a分支提交
git log a --oneline

c3c3c3c 提交3
b2b2b2b 提交2
a1a1a1a 提交1

# 按照顺序
git cherry-pick a1a1a1a b2b2b2b c3c3c3c

# 如果 提交是连续的:
	# a1a1a1a^ 表示提交 1 的前一个提交
	# .. 表示一个提交区间
git cherry-pick a1a1a1a^..c3c3c3c

learngitbranching

图解git

githowto

git飞行规则