常用命令
按使用频度排序
- 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
- git merge
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
git对应的功能是归档
mkdir ../working
git archive master | tar -x -C ../working
Git 高级功能
submodule
git submodule add 仓库地址 路径
git submodule update --init
git submodule update
fork后如何同步源的新更新 ?
git remote -v
- 如果里面只能看到你自己的两个源(fetch 和 push),那就需要添加主repo的源:
git remote add upstream URL
git remote -v
git fetch upstream
git merge upstream/master
git push
git 项目打包导出
示例, 项目中有为1.0的tag
git archive 1.0 | bzip2 > v1.0.tar.bz2
与 Gerrit 配合使用
提交代码审核 git push origin HEAD:refs/for/mybranch