git 使用分享
- git 命令行必备- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25- # 设置 alias 别名 
 git config --global alias.st "status"
 git config --global alias.ci "commit"
 git config --global alias.co "checkout"
 git config --global alias.br "branch"
 git config --global alias.ps "push"
 git config --global alias.pl "pull"
 git config --global alias.bra "branch -a"
 git config --global alias.cob "checkout -b"
 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 user.name "your name"
 git config --global user.email "ericrao@welove-inc.com"
 # 查看 git 配置
 $ cat .gitconfig
 [alias]
 co = checkout
 ci = commit
 br = branch
 st = status
 [user]
 name = Your Name
 email = your@email.com
- 配置 credential,避免每次都输入用户名和密码 - git config --global credential.helper store <file path>
 
- 忽略无用文件: - 推荐插件 .ignore on IDEA 
- .gitignoretemplates :https://github.com/github/gitignore
 
- 常用命令 git merge和git fecth / pull的区别
- 巧用保存进度 git stash和git stash pop / apply
- 每次发版需要打标签:- git tag 1.0.0 -m "tag message"
- 查看 TAG: git tag --list、git show 1.0.0
 
问题合集
- 问题 1:如何使用 submodule- 代码演示
 
- 问题 2 :如何使用 subtree- 比 submodule 更建议使用,具体使用方法待更新
 
- 问题3 :避免分支合并错误- 修改分支名 : master_stable / master_dev / master_debug / raomengyang_dev/ master_beta
- 使用 git hook :https://gist.github.com/mwise/69ec35b646b52d98050d
 
To use this hook:
- add the
prepare-commit-msgfile at.git/hooks/prepare-commit-msgand edit as needed- make it executable:
chmod +x .git/hooks/prepare-commit-msg- disable fast-forward merges:
git config branch.master.mergeoptions "--no-ff"- that’s it!
NOTE: after a failed merge from a forbidden branch, the working tree will still be in a MERGING state. To discard the local working copy state, run:
git reset --merge
| 1 | #!/usr/bin/env ruby | 
- 问题4 :
我本来打算把代码提交到branch1,但是我提交的时候忘了切过去, 提交到branch2了( 未推送或者已经推送 ), 这时候怎么回到我提交前的状态, 切个分支就可以再提交到branch1
 代码演示
- iOS 项目分支出的问题 -