总结一下git使用的积累
图形化软件使用
只用过sourcetree 确实很方便,pc,mac端都有客户端,每次提交前看一下提交的文件状态,可以很方便的看到自己对哪些文件进行了改动,另外文件对比功能,我选择的是Beyond Compare ,选中某个文件改动的文件 ctrl + d
就可以方便的启动beyond compare进行查看。 另外sourcetree
还可以很方便的查看一个文件的历史提交记录,并且可以查看他们之间的差异。有了这两个软件,就不用记那么多git的命令了,懒人必备。
sourecetree
这个软件使用的时候需要登录一个账户,尴尬的是这个账户注册的页面是需要梯子才可以方法的,pc端有一个绕过去的方法,很容易搜到,mac端就没那么教程了,很难解决,好在最后我学会了搭梯子,顺利的解决了这个问题,关于如何搭梯子,我在这里也做了记录。
beyond compare
很好用,但是是收费的,破解也不是很好破解,网上可以找一些方法,先用一段时间,不能用的时候在想办法,目前还没有找到一个可以完全破解的方法。
git-flow 简介

git鼓励开发者多利用分支进行开发,但是如何更加规范的创建和管理分支是需要开发团队提前约定好的,git-flow就是做这个事情的,按照git-flow打开发流程能够很好的协调好团队的开发流程,大家都遵守这个流程的话互相配合起来就会更加高效不容易出错了。
具体可以参考下面的文章
摘抄一些命令如下
git flow init
git flow feature start MYFEATURE
git flow feature publish MYFEATURE
git flow feature pull origin MYFEATURE
git flow feature finish MYFEATURE
git flow release start RELEASE [BASE]
git flow release publish RELEASE
git flow release finish RELEASE git push --tags
git flow hotfix start VERSION [BASENAME]
git flow hotfix finish VERSION
|
gerrit 简介
gerrit 是一个用来做code review的工具,对于开发团队来说CR也是非常重要的,比如线上改动的bug,如果需要进行CR的话可以很方便的在gerrit上进行,gerrit其实和私有的git服务器很类似,需要搭建一个gerrit服务器,每次check out 代码直接在gerrit上进行,然后提交代码也到gerrit上,gerrit会自动把自己的代码同步到绑定的git上去,前提是和gerrit和git上没有冲突,冲突出现的原因一般是有人不按照规范直接把代码提交打git上去了。
gerrit具体搭建过程可以在网上搜一下,很多。
gerrit搭建
git常用命令

虽然git有上面很好用的命令。但是一些简单的git命令,还是需要记住的。
我的常用命令
status
git branch [-a]
git remote -v
git stash
git stash pop
git diff --shortstat "@{0 day ago}"
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 lg git lg -p
git config --global alias.wc "diff --shortstat '@{0 day ago}'" git wc
|
下面是从阮老师那copy过来做备份的
新建代码库
$ git init
$ git init [project-name]
$ git clone [url]
|
配置
$ git config --list
$ git config -e [--global]
$ git config [--global] user.name "[name]" $ git config [--global] user.email "[email address]"
|
增加/删除文件
$ git add [file1] [file2] ...
$ git add [dir]
$ git add .
$ git add -p
$ git rm [file1] [file2] ...
$ git rm --cached [file]
$ git mv [file-original] [file-renamed]
|
代码提交
$ git commit -m [message]
$ git commit [file1] [file2] ... -m [message]
$ git commit -a
$ git commit -v
$ git commit --amend -m [message]
$ git commit --amend [file1] [file2] ...
|
分支
$ git branch
$ git branch -r
$ git branch -a
$ git branch [branch-name]
$ git checkout -b [branch]
$ git branch [branch] [commit]
$ git branch --track [branch] [remote-branch]
$ git checkout [branch-name]
$ git checkout -
$ git branch --set-upstream [branch] [remote-branch]
$ git merge [branch]
$ git cherry-pick [commit]
$ git branch -d [branch-name]
$ git push origin --delete [branch-name] $ git branch -dr [remote/branch]
|
标签
$ git tag
$ git tag [tag]
$ git tag [tag] [commit]
$ git tag -d [tag]
$ git push origin :refs/tags/[tagName]
$ git show [tag]
$ git push [remote] [tag]
$ git push [remote] --tags
$ git checkout -b [branch] [tag]
|
查看信息
$ git status
$ git log
$ git log --stat
$ git log -S [keyword]
$ git log [tag] HEAD --pretty=format:%s
$ git log [tag] HEAD --grep feature
$ git log --follow [file] $ git whatchanged [file]
$ git log -p [file]
$ git log -5 --pretty --oneline
$ git shortlog -sn
$ git blame [file]
$ git diff
$ git diff --cached [file]
$ git diff HEAD
$ git diff [first-branch]...[second-branch]
$ git diff --shortstat "@{0 day ago}"
$ git show [commit]
$ git show --name-only [commit]
$ git show [commit]:[filename]
$ git reflog
|
远程同步
$ git fetch [remote]
$ git remote -v
$ git remote show [remote]
$ git remote add [shortname] [url]
$ git pull [remote] [branch]
$ git push [remote] [branch]
$ git push [remote] --force
$ git push [remote] --all
|
撤销
$ git checkout [file]
$ git checkout [commit] [file]
$ git checkout .
$ git reset [file]
$ git reset --hard
$ git reset [commit]
$ git reset --hard [commit]
$ git reset --keep [commit]
$ git revert [commit]
$ git stash $ git stash pop
|
其他