git 常用

0 gitignore


# 此为注释 – 将被 Git 忽略

# 忽略所有 .a 结尾的文件
*.a

# 但 lib.a 除外
!lib.a

# 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
/TODO

# 忽略 target/ 目录下的所有文件
target/
dist/

# 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
doc/*.txt

# 忽略 doc/ 目录下所有扩展名为 txt 的文件
doc/**/*.txt

1. git本地配置

git config --global user.name "tiemaocsdn"
git config --global user.email "tiemaocsdn@qq.com"

2. git alias

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美化

// 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 

9. 版本回退

git reflog //所有版本历史

10. git 拉远程特定分支

git clone -b dev ${url}
  1. 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

17 git 查看项目配置,和配置项目

git config -e // 编辑当前项目的配置
git config user.email "1457896625@qq.com"

posted @ 2018-09-10 18:29  StarBugs  阅读(170)  评论(0编辑  收藏  举报