git 命令snippets
-
在本地切换远程分支
git checkout -b local_branch_name remote\origin\remote_branch_name
这个命令的意思是新建一个本地分支local_branch_name 来跟踪(track)一个远程分支remote_branch_name -
删除远程分支
git push origin --delete remote_branch_name -
设置别名或简化命令
(1)git config --global alias.st status
将status 命令简化为 st,--global是表示全局设定,省略后表示只设置当前的repo。
(2)git config --global alias.last 'log -1 HEAD'
显示最后一次提交。
这是git的别名设置,所以,git是不能省略的,在命令行里输入st是没用,还是要用git st -
使本地分支与远程分支一致
git branch -D branch_name | git checkout -b r2020/update3 remotes/origin/branch_name
note: 这里必须使用大写的D,可以删除那些未被merge的修改 -
查看当前分支的最新的commit id
git rev-parse HEAD -
查看特定commit 的parent id
git log --pretty=%p -n 1 commit_idgit cat-file -p commit_id
-
git 只下载最近的一次提交
git clone --depth=1 https://github.com/xx.git
如果又想获取完整的库
git fetch --unshallow
这是对于github在国内比较慢的一个解决方法。
https://github.com/tiimgreen/github-cheat-sheet
-
在 pull 或者checkout 的时候submodule 自动更新
git config --global submodule.recurse true -
保存账号密码
git config --global credential.helper store