git 積累

1、git  log 的用法,具體參考 git log --help,以下是個人在使用中遇見的問題,略作統計。

查看單個文件的修改差異(類似於查看單個文件的log,同時將每次log 的詳細記錄都顯示出來):

        git log --full-diff

Without this flag, git log -p <path>...shows commits that touch the specified paths, and diffs about the same specified paths. With this, the full diff is shown for commits that touch the specified paths; this means that "<path>…" limits only commits, and doesn’t limit diff for those commits.

清晰,精簡的log可以使用:

git log --abbrev-commit --pretty=oneline

$ git log -p  <path>... test.c
$ git log -u  <path>... test.c
$ git log -patch  <path>... test.c

具體查看,結合使用 -p --stat 效果更清晰,詳細參考git-log help的COMMAN DEFF OPTIONS
$ git log -p --stat <path>...test.c


2、git pull 或 git commit 出現如下錯誤,是因爲文件夾權限被修改
error: insufficient permission for adding an object to repository database .git/objects

只需修改下權限即可解決  sodu chrom 777 .git/objects/  -R


3、git  remote 遠程服務器路徑修改

如果(服務器)地址或者路徑更換,需重新鏈接到遠程服務器上,必須重新設置遠程服務器地址。

git remote -v  //查看遠程倉庫地址
git remote set-url origin (new_remote_git_address)  //遷移到新倉庫地址

new_remote_git_address : 新的遠程倉庫地址


4、git branch 分支操作

設置XXX分支爲遠程默認分支:git branch --set-upstream-to=origin/XXX

git branch 查看本地分支
    * dev (*當前位於dev分支)
    master 
git branch --remote 查看遠程分支
    origin/dev 
    origin/master
git checkout -b <new_branch> 創建分支
git checkout <another_branch> 切換分支 
git push origin <branch_name> push本地分支代碼到遠端服務器,如果沒有該分支,自動創建
git pull origin <branch_name> pull遠端分支代碼到本地對應分支
git checkout b_branch 刪除本地分支,首先切換到別的分支,然後才能刪除
git branch -d a_branch 
git push origin --delete branch_name 刪除遠程分支 
git merge b 合併本地分支,假設當前分支爲a,將本地的b分支代碼合併到a中
git merge origin/b 合併遠程分支,和前面的幾乎一樣


5、git bash 快速複製粘貼

在Bash命令界面,鼠標右擊Bash邊框上沿,Properties->Options->Edit Options->QuickEdit Mode 前面打上勾,就OK了。

Bash界面的快速複製粘貼默認是關閉了的,爲什麼,我也不知道!


6、錯誤:
$ git diff util/webkit/mkdist-webkit
diff --git a/util/webkit/mkdist-webkit b/util/webkit/mkdist-webkit
old mode 100755
new mode 100644

解決:
git config --global core.filemode false
git config core.filemode false
原因:權限問題


7、git cherry

如果你想確認本地commit的代碼是否push到服務器上時,可用

git cherry -v   //顯示本地commits但是未push的提交


8、git status

查看分支詳細狀態,同時會顯示本地commits,但是未push到服務器上的代碼。


9、 git clone -b <xx_branch> aaa.git

只clone xx_branch到本地,不clone其他分支,節約資源和分支。


10、git add

a)增加修改過文件到緩存區,commit前執行;commit 的時候不建議使用 -a

b)個人新增文件,提交前一定要先add


11、git clean 

清除未跟蹤文件

git log 的用法很多,慢慢累積,也在此慢慢記錄。

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