目录

git 常用命令

shell

git clone -b v5.12 git@gitee.com:xxx/xxx.git

shell

git log --graph --pretty=oneline --abbrev-commit

shell

git remote add origin git@github.com:michaelliao/learngit.git

shell

git push -u origin master

shell

git diff readme.txt

shell

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>可以删除一个远程标签。

shell

git log --since="6am"

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 错误

解决方案:

shell

git config --global core.ignorecase false

win上会提示CRLF will be replaced by LF

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

shell

git config --global core.autocrlf input

shell

git commit --amend

shell

git config core.quotepath false  --global

shell

git push origin -d 
git remote prune origin

shell

git checkout fileName
// or
git checkout .

shell

# 删除文件
rm filename

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

# 同上,但是还会处理文件夹
git clean -xdff

shell

git reset HEAD <fileName>

shell

git add fileName 
git commit -amend -m '说明'

shell

git reset [--hard|soft|mixed|merge|keep] [commit|HEAD]

shell

# 查看文件版本
git log <filename>
git checkout <commitID> <fileName>

shell

git revert HEAD // 是反做了目标版本,产生一个新的commits

git reset --hard HEAD^ // 会删除目标版本后的版本

learngitbranching

图解git

githowto

git飞行规则