常用commit格式
git commit -am "xxx"
GIT的配置文件
- /etc/gitconfig
- ~/.gitconfig or ~/.config/git/config
- .git/config
GIT全局配置信息
配置基本信息
git config --global user.name 'jinhongliang'
git config --global user.email jinhongliang2@huawei.com
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.ci commit
配置文本编辑器
git config --global core.editor emacs
查看全局配置
git config --list
GIT文件状态
- Untracked
- Tracked
- Unmodified
- Modified
- Staged
.gitignore文件格式规范
- 所有空行或者以 # 开头的行都会被 Git 忽略
- 可以使用标准的 glob 模式匹配
- 匹配模式可以以(/)开头防止递归
- 匹配模式可以以(/)结尾指定目录
- 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(!)取反
git操作
列出标签
git tag
git tag -l 'v1.8.5*'
git show v1.4`
创建标签
git tag -a v1.4 -m 'my version 1.4'
git tag v1.1
git tag -a v1.1 [commit-id]
推送标签到远程仓库
git push origin [tagname]
git push origin --tags
撤销修改操作
git chekcout -- [file]
撤销暂存操作,保留修改操作
git reset HEAD [file]
删除文件
git rm [file]
删除已经修改,并且放入暂存区的文件
git rm -f [file]
只删除暂存区的文件,不删除当前文件下的
git rm --cached [file]
可以使用glob模式
git rm log/\*.log
(注意反斜杠)
修改名称
git mv [file1] [file2]
or
mv [file1] [file2] git rm [file1] git add [file2]
克隆库
git clone [url]
git clone [url] [local_name]
初始化git
git init
查看帮助文件
git help <verb>
git <verb> --help
man git-<verb>
查看远程仓库
git remote
git remote -v
git remote show [remote-name]
设置远程仓库
git remote add -f gerrit ssh://j00418659@cloudos-review.huawei.com:29418/cloudos/neutron-nat-monitor
从远程仓库获得没有的数据(并不会合并本地修改)
git fetch [remote-name]
从远程仓库获得没有的数据,自动尝试合并(分支追踪远程分支)
git pull
将本地的xxx分支合并到远程的主分支上
git push [remote-name] [branch-name]
远程仓库重命名
git remote rename [remote-name] [remote-name1]
移除远程仓库
git remote rm [remote-name]
git reset撤销操作
git relog
git reset --hard commit-id
在branch上面增加topic
git push origin HEAD:refs/for/master/<topic_name>
git review -t optimize_snat
更新代码到本地
git pull origin master
更新代码到远程库
首先切换到分支develop
git checkout -b FE2017081700009-1 origin/master
查看本地修改
git status
git status -s
git status --short
删除修改
git checkout -- .
本地增加修改
git add .
本地提交
git commit -m "xxx"
跳过暂存阶段直接commit
git commit -a -m 'xxx'
远程提交
git review
查看本地分支
git branch
git branch -a
查看分支提交
git branch -v
查看合并到当前分支的分支
git branch --merged
git branch --no-merged
删除本地分支
git branch -d branch-name
git branch -D branch-name
强制删除分支
查看历史commit
git log
查看每次提交差异,查看最近2次提交
git log -p -2
查看log的简略统计信息
git log --stat
不同格式查看log
git log --pretty=[oneline|short|full|fuller]
定制格式查看log
git log --pretty=format:"xx-xx-xx"
回滚到以前的commit
git reset --hard "commit-id"
%H---提交对象(commit)的完整哈希字串
%h---提交对象的简短哈希字串
%T---树对象(tree)的完整哈希字串
%t---树对象的简短哈希字串
%P---父对象(parent)的完整哈希字串
%p---父对象的简短哈希字串
%an---作者(author)的名字
%ae---作者的电子邮件地址
%ad---作者修订日期(可以用 --date= 选项定制格式)
%ar---作者修订日期,按多久以前的方式显示
%cn---提交者(committer)的名字
%ce---提交者的电子邮件地址
%cd---提交日期
%cr---提交日期,按多久以前的方式显示
%s---提交说明
显示最近两周内的提交
git log --since=2.weeks
图形化显示log
git log --pretty=oneline --graph
满足所有搜索条件
git log ... --all-match
涉及字符串添加或移除的log
git log -Sxxxx
查看具体文件的修改log
git log -- [file]
切换分支
git checkout branch-name
git checkout -b new_branch
查看当前和未暂存的修改
git diff
查看当前和暂存的修改
git diff --cached
git diff --staged
git diff插件
git difftool --tool-help
重新提交
git commit --amend
查看远程仓库的分支
git branch -a/git branch -r
查找某内容的改变
git log -S "xxx"
查看某个commit的改变
git show commit-id
git diff commit-id^
网友评论