码迷,mamicode.com
首页 > 其他好文 > 详细

git 笔记

时间:2015-10-17 20:45:23      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:

以下笔记摘自 廖雪峰的GIT教程,由于经常忘记某些命令,特记于此,方便查阅.

1.设置用户名和邮箱(page 13)

  git config --global user.name "your name"

  git config --global user.email "youremail@xx.com"

2.创建版本库(page 14)

  git init

注意:不要用windows自带记事本编辑文件, 推荐notepad++并设置格式为 UTF-8 without BOM

3.添加文件(page 15)

  git add filename

  git add .      添加目录下的所有文件

4.提交(page 15)

  git commit -m "comment"

5.查看仓库状态(page 17)

  git status

6.对比文件(page 17)

  git diff filename

  git diff     所有文件

7.历史记录(page 19)

  git log

  git log --pretty=oneline  (精简模式)

8.回退(page 20)

  git reset --hard commit_id    (commit_id为版本号,只需输入前几位数字, 当前版本用HEAD^)

9.命令记录(page 22)

  git reflog

10.查看工作区和版本库中文件的差别(page 29)

  git diff HEAD -- filename

11.撤销工作区中的修改(page30)

  git checkout -- filename

12.从版本库中删除文件(page 33)

  git rm filename

  恢复误删的文件 

  git checkout -- filename

13.添加远程库(page 38)

  git remote add origin xxxaddressxxxx.git

  origin 为git默认的名字

14.推送到远程库(page39)

  git push -u origin master          -u:把本地的和远程的master关联

15.从远程库克隆(page42)

  git clone git@...git  或 https:xxx.git

16.创建分支(page 46)

  git checkout -b branchname   =  git branch branchname    git checkout branchname

17.查看所有分支(page46)

  git branch

18. 合并分支(page47)

  git merge branchname    (快进模式, 指针直接移动)

19.删除分支(page47)

  git branch -d branchname

20.合并冲突(page51)

  修改冲突的文件后再add和commit

21.查看分支合并情况(page51)

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

22.合并分支,非快进模式(page53)

  git merge --no-ff -m "comment" branchname

23.分支管理(page54)

  master和dev, 每个人有独立的分支, 每个BUG建个临时分支issue-01, 合并后删除

24.临时存储工作区(page55)

  git stash

  git stash list 

  git stash pop  (恢复)

25.恢复指定的stash(page57)

  git stash apply stash@{0}

26.强行删除分支(page58)

  git branch -D branchname

27.远程库信息(page60)

  git remote

  git remote -v

28.远程分支(page60)

  从本地推送分支  git push origin master

  在本地创建与远程分支对应的分支   git checkout -b branchname origin/branchname 

  建立本地分支与远程分支的关联  git branch --set-upstream branchname origin/branchname

29.标签管理(page64)

  git tag v1.0

  git tag     查看所有标签

30.根据历史提交打标(page65)

  先找到历史记录 git log --pretty=oneline --abbrev-commit 

  然后 git tag v0.9 commit_id

  可以加上说明 git tag v0.9 commit_id -m "comment"

31.删除标签(page68)

  git tag -d v0.1

32.推送某个标签到远程(page68)

  git push origin v0.1

  git push origin tags   所有标签

33.删除远程标签

  先删本地 git tag -d v0.9

  git push origin :refs/tags/v0.9

34. 让git 显示颜色(page70)

  git config --global color.ui true

35.忽略特殊文件(page71)

  .gitignore    文件

36.配置别名(page73)

  git config --global alias.st status

  git st  = git status

37.试试这个配置(page74)

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"

 

38. 搭git服务器(page 75)

 

其它命令:

a.制作patch

  git diff master > patch

     应用patch

  git apply patch

 

 

  

  

  

 

git 笔记

标签:

原文地址:http://www.cnblogs.com/davidlong/p/4888123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!