学习地址传送门:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
笔记(部分是自己扩展的):
1、查看版本:
git log
“
git log命令显示从最近到最远的提交日志,我们可以看到3次提交,最近的一次是“append GPL”,上一次是“add distributed”,最早的一次是“wrote a readme file”。 如果嫌输出信息太多,看得眼花缭乱的,可以试试加上 --pretty=oneline参数
”
2、版本回退:
git reset --hard HEAD^
HEAD表示当前版本,如果往前回退n个版本,则 :git reset --hard HEAD(这里是n个^,或者“~n”)。
3、执行命令记录:
git reflog
如果失误从a退回到以前的版本b、想要回来,同时找不到a的版本号,那么用这个命令。
4、指定版本号对拍文件:
git diff 版本号1 版本号2 文件名
5、用指定版本中的文件a、替换当前的文件a:
git checkout 版本号 -- 文件名
6、创建ssh key:
ssh-keygen -t rsa -C "youremail@example.com"
“
如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
”
7、用带参数的git log查看分支合并情况:
git log --graph --pretty=oneline --abbrev-commit
8、不是使用Fast forward模式来合并:
git merge --no-ff -m (commit -m的内容) (分支名)
9、查看远程库信息:
git remote
git remote -v
后者显示详细信息。
10、指定本地分支与远程分支的链接:
git branch --set-upstream 分支名 origin/<分支名>
有时候git pull会提示提示“no tracking information”,这是因为说明本地分支和远程分支的链接关系没有创建,那么使用这个命令,然后再pull。
11、从远程分支抓取指定分支:
git checkout -b branch-name origin/branch-name
常用:
(1)删除分支:
git branch -d 分支名
(2)储藏分支状态:
储藏该分支当前的修改:git stash;
唤回该储藏:git stash list查看;
唤回方式1. git stash apply 缺点,stash内容并不删除,需要用git stash drop来删除
唤回方式2. git stash pop 唤回的同时删除stash里面的内容
注:可多次stash,使用:git stash apply stash@{0} 恢复
(3)标签:
1.对当前分支的当前版本打标签:git tag 标签名;
2.对指定版本打标签:git tag 标签名 版本号;
3.查看所有标签:git tag;
4.查看指定标签:git show 标签名;
5.创建带有说明的标签:git tag -a 标签名 -m "说明信息" 版本号(-a表示标签名、-m表示说明信息);
6.s用私钥签名一个标签,不过这个签名必须安装gpg(GnuPG):git tag -s 标签名 -m "说明信息" 版本号。
标签删除:
1.本地删除指定标签:git tag -d 标签名;
2.推送指定标签:git push origin 标签名;
3.推送所有标签:git push origin --tags;
4.删除远程标签(这个麻烦点儿):
先删除本地标签:git tag -d 标签名;
然后删除远程的:git push origin :refs/tags/标签名。
技巧:
1、显示颜色:git config --global clolor.ui true
2、取别名:git config --global alias.别名 真名
注:--global是全局参数,表示在该电脑下所有的git仓库都起作用。
我的配置:
> 别名:
git config --global alias.st status
git config --global alias.ch checkout
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.unstage 'reset HEAD'
git config --global alias.last 'log -1'
> 彩色:
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
> 有一个丧心病狂的别名配置:
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小抄:
From:purple尘