git

1. git add 添加文件到staged area.
2. git commit 會commit staged file ,有幾個選項比較重要:-a 跳過staged area,直接commit,後面加文件名也會使那個文件跳過stage,直接commit。但是前提是文件已經在index中了,新文件不會自動加入。
3.git status 查看從上次commit到目前的變化,git diff會更詳細,但是它只包含應該要包含在staged area中卻還未包含進去的變化,git diff --staged則列出來從上次commit到staged area的變化。
4. .gitignore文件可以設置哪些文件被排除進去,通常可以設.o, .a等文件。
5. git rm 用來remove文件。
6. git mv可以用來重命名文件。
7. git log用來查看日誌,git log -p查看詳細,gitk 是個圖形化的查看工具。
8.Unstaging a Staged File可以用git reset HEAD <file>。 Unmodifying a Modified File可以用git checkout -- <file>。 git commit --amend用來取消上次的commit。
9. git remote顯示所有的remote(加-v顯示詳細信息)。
git remote add [shortname] [url]用來添加remote。 git fetch [remote-name]只會pull下來全部的更動,但不會自動merge,但是git pull會自動merge。 git remote show [remote-name]可以看到一個remote的詳細信息。 git remote rename用來改變一個remote的名字。 git remote rm刪除一個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衝突的uncommitted changes.
13. git merge branch-name 將branch-name merge到當前branch.如果有conflict,可以用status查看狀態,解決conflict之後用add 通知git已經解決。然後用commit commit the merge。
14.
  git branch -d branch-name,但是這個branch必須被全部merge到HEAD中了。如果選項是-D的化,就不管它的merge status了。
15. git branch --merged只顯示被HEAD完全包含的branch,--no-merged只顯示沒被HEAD完全包含的branch。
16.
git push (remote) (branch)把本地某個branch push到remote上去。 git push (remote) (local-branch-name):(remote-branch-name)可以把本地branch push到remote branch上去。
17.git fetch 下載下來的branch不能edit,必須要手動merge到本地branch之後纔可以edit。
  $ git checkout -b local-branch-name remote-name/remote-branch-name 可以把server上的branch下載下來,並且可以直接edit。
18.
Tracking Branches裏面可以不必在pull和push後面加remote參數。git branch -r列出remote tracking branches.
19. git push [remotename] :[remote-branch]刪除掉某個remote branch。
20. rebase可以獲得和merge一樣的效果,但是log記錄更好,因爲看起來沒有分支。
git rebase --onto newbase upstream branch會把從upstream到branch的改動rebase到newbase上去。git rebase basebranch topicbranch會把topicbranch rebase到basebranch上。
21.
Do not rebase commits that you have pushed to a public repository.

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章