1. git add 添加文件到staged area.

2.gitcommit会commitstagedfile,有几个选项比较重要:-a跳过stagedarea,直接commit,后面加文件名也会使那个文件跳过stage,直接commit。但是前提是文件已经在index中了,新文件不会自动加入。

3.gitstatus查看从上次commit到目前的变化,gitdiff会更详细,但是它只包含应该要包含在stagedarea中却还未包含进去的变化,gitdiff--staged则列出来从上次commit到stagedarea的变化。

4..gitignore文件可以设置哪些文件被排除进去,通常可以设.o,.a等文件。

5.gitrm用来remove文件。

6.gitmv可以用来重命名文件。

7.gitlog用来查看日志,gitlog-p查看详细,gitk是个图形化的查看工具。

8.UnstagingaStagedFile可以用gitresetHEAD<file>。UnmodifyingaModifiedFile可以用gitcheckout--<file>。gitcommit--amend用来取消上次的commit。

9.gitremote显示所有的remote(加-v显示详细信息)。gitremoteadd[shortname][url]用来添加remote。gitfetch[remote-name]只会pull下来全部的更动,但不会自动merge,但是gitpull会自动merge。gitremoteshow[remote-name]可以看到一个remote的详细信息。gitremoterename用来改变一个remote的名字。gitremoterm删除一个remote。

10.git tag列出所有的tag。git show tag-name可以查看tag详细信息。git tag [-a] tag-name -m message [commit-checksum]如果有-a 就添加一个annotated tag,如果没有-a,就添加一个lightweight tag,如果后面要在某个commit之后添加一个tag,就加上checksum好了。 git push有个选项 --tags会把tags信息也push上去。

11.git branch testing添加一个testing的branch.git checkout testing切换到testing branch.

     git branch -b branchname tagname  

     git push origin branchname               // push remote branch for one tagname

     git branch --track branchname   |git baanch branchname origin/branchname

      // checkout branchname

git checkout --track origin/branchname

12.切换branch的时候,当前的branch不能有和要切换过去的branch冲突的uncommittedchanges.

13.gitmergebranch-name将branch-name merge到当前branch.如果有conflict,可以用status查看状态,解决conflict之后用add 通知git已经解决。然后用commitcommitthemerge。

14.

gitbranch-dbranch-name,但是这个branch必须被全部merge到HEAD中了。如果选项是-D的化,就不管它的mergestatus了。

15.gitbranch--merged只显示被HEAD完全包含的branch,--no-merged只显示没被HEAD完全包含的branch。

16.gitpush(remote)(branch)把本地某个branchpush到remote上去。gitpush(remote)(local-branch-name):(remote-branch-name)可以把本地branchpush到remotebranch上去。

17.gitfetch下载下来的branch不能edit,必须要手动merge到本地branch之后才可以edit。$gitcheckout-blocal-branch-nameremote-name/remote-branch-name可以把server上的branch下载下来,并且可以直接edit。

18.TrackingBranches里面可以不必在pull和push后面加remote参数。gitbranch-r列出remotetrackingbranches.

19.gitpush[remotename]:[remote-branch]删除掉某个remotebranch。

20.rebase可以获得和merge一样的效果,但是log记录更好,因为看起来没有分支。gitrebase --ontonewbaseupstreambranch会把从upstream到branch的改动rebase到newbase上去。git rebasebasebranchtopicbranch会把topicbranchrebase到basebranch上。

21.Donotrebasecommitsthatyouhavepushedtoapublicrepository.

22.git fetch默认会获取repo所有branch的进度,除非指定哪个branch。git push可以将某个branch push到repo中去。

23、 git reset --hard HEAD~3   会将最新的3次提交全部重置,就像没有提交过一样。

24、git stash — 暂存临时代码

可以将你当前未提交到本地(和服务器)的代码推入到Git的栈中,这时候你的工作区间和上一次提交的内容是完全一样的,所以你可以放心的修 Bug,等到修完Bug,提交到服务器上后,再使用’git stash apply’(stash中还有备份)将以前一半的工作应用回来。或者用"git stash pop"来将改的应用返回来,此时stash中清空 ,相当于调用了git stash clear来清空stlash

25、git config --global user.name="weina"

       git config --global user.email=''[email protected]" 配置全局的name和email,以便再提交的时候,能看到是谁提交的

26、clone porject   用git clone username@ip:29418/projectPath 拷贝项目

      使用 scp -p -P 29418 yourdomain:hooks/commit-msg .git/hooks/拷贝到你的项目中,可以通过commit后 gitk   查 看log日志有没有相应的changeId来确认。如果不拷贝这个hooks,在提交到gerrit时很容易发生错误。

27、使用utf8确定commit的字符集修改GIT_HOME/etc/gitconfig文件增加

      [gui]

      encoding=utf-8

     [i18n]

     commitencoding=utf-8

   logoutputencoding=utf-8