常用命令
按使用频度排序
- git pull
- git log
- git diff
- git commit
- git commit --amend
- git review
- git clone
- git push
- git reset --hard/soft
- git checkout
- git fetch --all
- git merge
- git branch -b develop origin/develop
git 命令非常多,但常用的只有以上几个
常用配置
- 用户名和密码
$ git config --global user.name liuzuocheng
$ git config --global user.email zuocheng.liu@gmail.com
- 默认编辑器
$ git config --global core.editor vim
- 配置比较工具
git config --global merge.tool vimdiff
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool
- 或者直接更改配置文件 ~/.gitconfig,添加手工添加配置
常用经验
- 将远程主干合并到本地分支
在代码上线前,这一步非常重要
git fetch && git rebase origin/master
git fetch --all && git merge origin master
- 解决版本冲突
暂存本地修改
$ git stash
拉取版本库中最新版本
$ git pull
将本地修改与版本库中最新版本合并
$ git stash pop stash@{0}
解决冲突,使用下面的工具会非常方便
$ git d
- 将源码导出tar包
git对应的功能是归档
mkdir ../working
git archive master | tar -x -C ../working
Git 高级功能
submodule
git submodule add 仓库地址 路径
git submodule update --init
git submodule update
fork后如何同步源的新更新 ?
- 首先要先确定一下是否建立了主repo的远程源
git remote -v
- 如果里面只能看到你自己的两个源(fetch 和 push),那就需要添加主repo的源:
git remote add upstream URL
- 查看主repo的远程源
git remote -v
- 拉取主repo源的代码
git fetch upstream
- 合并
git merge upstream/master
- 提交
git push
git 项目打包导出
示例, 项目中有为1.0的tag
git archive 1.0 | bzip2 > v1.0.tar.bz2
示例,打包master分支
git archive --format tar.gz --output "../project.tar.gz" master
与 Gerrit 配合使用
提交代码审核 git push origin HEAD:refs/for/mybranch
转载请注明来源,原地址保持永久更新。
博客首页:作程的技术博客
文章标题:《Git 使用经验总结》
本文链接:https://it.zuocheng.net/git-use-experience-zh
来看看你,顺便给自己博客做个广告 http://lvheyang.com
你要是在我发过的,水平比较高的博客上留言,那多好
^_^