git 使用笔记

1. 开启工作区

git init 初始化git仓库 
git clone url 复制一个仓库 
git help 查看帮助 

2. git add

在提交之前,Git有一个暂存区(staging area),可以放入新添加的文件或者加入新的改动. commit时提交的改动是上一次加入到staging area中的改动,而不是我们disk上的改动.
git add .
会递归地添加当前工作目录中的所有文件.
git add index.js  将index.js修改提交到本地暂存区
git add -A  提交所有变化
git add -u  提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
git add .  提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件

3. git config

在git中,我们使用git config 命令用来配置git的配置文件,git配置级别主要有以下3类:
1、仓库级别 local 【优先级最高】
2、用户级别 global【优先级次之】
3、系统级别 system【优先级最低】

git config --(local/global/system) -l 查看仓库配置
git config --(local/global/system) -e 编辑仓库配置
git config user.name "tom"
git config user.email "hhh@qq.com"
git config --global alias.ci commit
git config --global alias.a "add -A"
// 别名配置 
git config --global alias.a 'add -A' 
git config --global alias.b branch  
git config --global alias.c  "commit -m" 
git config --global alias.ck checkout 
git config --global alias.st status

3. git log美化


  • %H 提交对象(commit)的完整哈希字串

  • %h 提交对象的简短哈希字串

  • %T 树对象(tree)的完整哈希字串

  • %t 树对象的简短哈希字串

  • %P 父对象(parent)的完整哈希字串

  • %p 父对象的简短哈希字串

  • %an 作者(author)的名字

  • %ae 作者的电子邮件地址

  • %ad 作者修订日期(可以用 --date= 选项定制格式)

  • %ar 作者修订日期,按多久以前的方式显示

  • %cn 提交者(committer)的名字

  • %ce 提交者的电子邮件地址

  • %cd 提交日期

  • %cr 提交日期,按多久以前的方式显示

  • %s 提交说明

// log美化
git config --global alias.lg "log --no-merges --color --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"

// stash list 美化
git config --global alias.shs '
list --pretty=format:"%C(red)%h%C(reset) - %C(dim yellow)(%C(bold magenta)%gd%C(dim yellow))%C(reset) %<(70,trunc)%s %C(green)(%cr) %C(bold blue)<%an>%C(reset)"'

4. 冲突显示 vim 编辑

`Please enter a commit message to explain why this merge is necessary,especially if it merges an updated upstream into a topic branch。`
先按esc 
:wq 推出 

5. 初始化git的文件

readme.md 
.gitignore
lisense

6. 撤销修改

// 撤销demo.txt的修改(和上次commit的)
git checkout demo.txt 

7. 保存本地更改 merge后提交

git stash  // 保存本地更改
git stash save -a "messeag" //
git stash list 
git stash pop --index stash@{0}
git stash apply stash@{id} //和pop一样,但是会保存stash记录 
git stash clear // 清空
git stash drop // 删上一条

8. 本地创建分支

git checkout -b dev 

// 克隆远程分支创建本地dev
git checkout -b dev origin/dev

9. 版本回退

git reflog //所有版本历史

git reset --hard hash

10. git 拉远程特定分支

git clone -b dev ${url}

11. delete 分支

git br -D bambaoo

12. 查看当前跟踪的分支

git br -vv

13. cherry-pick

pick其中的一个分支的一次提交,合并到当前分支 

git cherry-pick 08ru289

14. 修改提交信息

git commit --amend -m "update"

15 git 回退文件到某个版本

git checkout 5dc1bc214 templates/publish_advertisement.html

16 git认证失败 储存密码

git config --system --unset credential.helper

//长期存储密码:
git config –global credential.helper store

相关文章

Git安装和使用 Git安装和使用 刚开始用git的小白适用,,转自...
fatal: remote origin already exists.解决方法 第一个问题g...
git常用命令(二)查看历史记录 git log [--pretty=oneline]...
git之如何把本地文件上传到远程仓库的指定位置 git专栏收录该...
代码规范之 lint-staged 在代码提交之前,进行代码规则检查能...
方法:1、文件没有git操作时用“git checkout--文件”命令还...