這篇博客總結的也不錯:html
8 Tips to help you work better with Gitlinux
Git與Repo入門github
git-cheat-sheet.pdfshell
git config --global user.name "John Doe" git config --global user.email johndoe@example.com git config --global core.editor vim git config --global color.ui true git config --global alias.co checkout git config --global alias.br branch git config --global alias.ci commit git config --global alias.st status #Delete local branches that have been removed from remote on fetch/pull git config --global fetch.prune true git config --global alias.show-graph 'log --graph --abbrev-commit --pretty=oneline'
更多配置,請參考:Git tips and tricks服務器
下面是一份配置好的.gitconfig:工具
[user] name = Peng Donglin email = dolinux.peng@gmail.com [alias] ci = commit st = status co = checkout br = branch d = difftool
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
lol = log --graph --decorate --pretty=oneline --abbrev-commit [core] editor = vim [color] ui = true [sendemail] smtpserver = /usr/bin/msmtp confirm = auto [diff] tool = vimdiff [difftool] prompt = false [merge] tool = vimdiff [mergetool] prompt = false
使用vimdiff做爲 git diff工具gitlab
git config --global diff.tool vimdiff git config --global difftool.prompt false git config --global alias.d difftool
而後使用 git d 打開對比代碼,而後用 :wq 繼續比較下一個文件。post
git difftool $start_commit..$end_commit -- path/to/file
git merge時使用vimdiff
git config --global merge.tool vimdiff git config --global mergetool.prompt false
*.a # 忽略全部 .a 結尾的文件
!lib.a # 但 lib.a 除外
/TODO # 僅僅忽略項目根目錄下的 TODO 文件,不包括 subdir/TODO
build/ # 忽略 build/ 目錄下的全部文件
doc/*.txt # 會忽略 doc/notes.txt 但不包括 doc/server/arch.txt
git diff --cached
git diff
git diff $start_commit..$end_commit -- path/to/file
git diff $start_commit..$end_commit
To remove all tracking branches that you have locally but are no more present in the remote repository (origin
):
git remote prune origin
Use the --dry-run
flag to only see what branches will be pruned, but not actually prune them:
git remote prune origin --dry-run
git rm --cached readme.txt
git log --stat
git log --stat dd257933fa4b9fea66a1195f8a15111029810abc -1$git log --pretty=oneline 694d0d0bb2030d2e36df73e2d23d5770511dbc8d Linux 4.8-rc2 0043ee40f98d15a50721fbd5dbf7c7797f8d03cd Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
4ef870e373382f18de214f61e5d5eb83b62b7aa5 Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
$git log --author="Linus Torvalds" commit 694d0d0bb2030d2e36df73e2d23d5770511dbc8d Author: Linus Torvalds <torvalds@linux-foundation.org> Date: Sun Aug 14 19:11:36 2016 -0700 Linux 4.8-rc2 commit 0043ee40f98d15a50721fbd5dbf7c7797f8d03cd Merge: 4ef870e 1577ddf Author: Linus Torvalds <torvalds@linux-foundation.org> Date: Sun Aug 14 19:01:31 2016 -0700 Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
Pull thermal updates from Zhang Rui:
若是想過濾掉這個人的merge記錄,能夠用 git log --author="Linus Torvalds" --no-merges
git reset HEAD readme.txt
git remote show origin
git blame -L 12,22 simplegit.rb
git blame -w # ignores white space git blame -M # ignores moving text git blame -C # ignores moving text into other files
git checkout commit-id file_name
git push origin --tags
git push --all origin
git clean -n 顯示 將要 刪除的 文件 和 目錄
git clean -f 刪除當前目錄下全部沒有track過的文件. 他不會刪除.gitignore文件裏面指定的文件夾和文件, 無論這些文件有沒有被track過.
git clean -df 刪除當前目錄下沒有被track過的文件和文件夾
git clean -xfd 刪除當前目錄下全部沒有track過的文件. 無論他是不是.gitignore文件裏面指定的文件夾和文件.
在給linux kernel提交patch的時候通常都使用git send-email。
能夠用用下面的命令安裝git send-mail:
sudo apt-get install git-email
使用網易的163郵箱配置的方法:
1. 打開網易郵箱的設置界面,查看一下smtp的服務器的地址,以下圖所示:
2. 修改.gitconfig,以下:
[user] email = pengdonglin137@163.com name = Donglin Peng [sendemail] smtpserver = smtp.163.com smtpserverport = 587 smtpuser = pengdonglin137@163.com smtpencryption = ssl confirm = auto
3. 測試
$git send-email 0001-ASoC-dpcm-print-dai_link-name-of-BE-other-than-FE.patch --to pengdonglin137@163.com 0001-ASoC-dpcm-print-dai_link-name-of-BE-other-than-FE.patch (mbox) Adding cc: Donglin Peng <pengdonglin@smartisan.com> from line 'From: Donglin Peng <pengdonglin@smartisan.com>' (body) Adding cc: Donglin Peng <pengdonglin@smartisan.com> from line 'Signed-off-by: Donglin Peng <pengdonglin@smartisan.com>' From: Donglin Peng <pengdonglin137@163.com> To: pengdonglin137@163.com Cc: Donglin Peng <pengdonglin@smartisan.com> Subject: [PATCH] ASoC: dpcm: print dai_link name of BE other than FE. Date: Mon, 26 Sep 2016 17:55:36 +0800 Message-Id: <20160926095536.5890-1-pengdonglin137@163.com> X-Mailer: git-send-email 2.9.3 Send this email? ([y]es|[n]o|[q]uit|[a]ll): y Password for 'smtp://pengdonglin137@163.com@smtp.163.com:587': OK. Log says: Server: smtp.163.com MAIL FROM:<pengdonglin137@163.com> RCPT TO:<pengdonglin137@163.com> RCPT TO:<pengdonglin@smartisan.com> From: Donglin Peng <pengdonglin137@163.com> To: pengdonglin137@163.com Cc: Donglin Peng <pengdonglin@smartisan.com> Subject: [PATCH] ASoC: dpcm: print dai_link name of BE other than FE. Date: Mon, 26 Sep 2016 17:55:36 +0800 Message-Id: <20160926095536.5890-1-pengdonglin137@163.com> X-Mailer: git-send-email 2.9.3 Result: 250 Mail OK queued as smtp5,D9GowAAnL4ea8OhXVnd4Cw--.197S2 1474883745
4. 下面是收件箱的內容:
5. 向linux社區提交patch的時候,發送的郵件必須是純文本格式,而不能是HTML格式。
6. 能夠參考內核文檔:https://www.kernel.org/doc/Documentation/SubmittingPatches
7. 能夠參考博客:
http://files.cnblogs.com/files/pengdonglin137/Linux_community_and_Upstream_Linux_Codes.pdf
http://blog.sina.com.cn/s/blog_936739790102v5eu.html
git archive --format=tar.gz --prefix=Linux-3.16/ v3.16 > Linux-3.16.tar.gz
git archive --format=tar.gz --prefix=Linux-4.17/ 29dcea88779c856c7dc92040a0c01233263101d4 > Linux-4.17.tar.gz
repo start <topic_name>
開啓一個新的主題,其實就是每一個Project都新建一個分支
repo init -u <url> [OPTIONS]
在當前目錄下初始化repo,會在當前目錄生生成一個.repo目錄,像Git Project下的.git同樣,-u指定url,能夠加參數-m指定manifest文件,默認是default.xml,.repo/manifests保存manifest文件。.repo/projects下有全部的project的數據信息,repo是一系列git project的集合,每一個git project下的.git目錄中的refs等目錄都是連接到.repo/manifests下的。
repo manifest
能夠根據當前各Project的版本信息生成一個manifest文件
repo sync [PROJECT1...PROJECTN]
同步Code。
repo status
查看本地全部Project的修改,在每一個修改的文件前有兩個字符,第一個字符表示暫存區的狀態。
- | no change | same in HEAD and index |
A | added | not in HEAD, in index |
M | modified | in HEAD, modified in index |
D | deleted | in HEAD, not in index |
R | renamed | not in HEAD, path changed in index |
C | copied | not in HEAD, copied from another in index |
T | mode changed | same content in HEAD and index, mode changed |
U | unmerged | conflict between HEAD and index; resolution required |
每二個字符表示工做區的狀態
letter | meaning | description |
---|---|---|
- | new/unknown | not in index, in work tree |
m | modified | in index, in work tree, modified |
d | deleted | in index, not in work tree |
repo prune <topic>
刪除已經merge的分支
repo abandon <topic>
刪除分支,不管是否merged
repo branch或repo branches
查看全部分支
repo diff
查看修改
repo upload
上傳本地提交至服務器
repo forall [PROJECT_LIST]-c COMMAND
對指定的Project列表或全部Project執行命令COMMAND,加上-p參數可打印出Project的路徑。
repo forall -c 'git reset --hard HEAD;git clean -df;git rebase --abort'
這個命令能夠撤銷整個工程的本地修改。
好比:
把全部的庫切換分支: repo forall -c git checkout branch_name
刪除全部庫的某個分支: repo forall -c git branch -D branch_name
實例: repo forall -c "git co aosp/o-preview -b o-preview"
==