work:git-guide
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
work:git-guide [2010/07/17 18:00] – created percy | work:git-guide [2016/11/04 16:55] – percy | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== 收集一些git教程和常用命令 ====== | ====== 收集一些git教程和常用命令 ====== | ||
+ | |||
+ | |||
+ | |||
- http:// | - http:// | ||
+ | |||
+ | |||
+ | |||
- git 中文教程: | - git 中文教程: | ||
+ | |||
+ | |||
+ | |||
- Git 原始碼管理: | - Git 原始碼管理: | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 8: | Line 32: | ||
===== git常用命令速查 ===== | ===== git常用命令速查 ===== | ||
+ | |||
+ | |||
+ | |||
< | < | ||
+ | |||
+ | |||
+ | |||
git init # 開始用 Git 來管理 | git init # 開始用 Git 來管理 | ||
+ | |||
+ | |||
+ | |||
git add . # 把所有檔案加入 Git | git add . # 把所有檔案加入 Git | ||
+ | |||
+ | |||
+ | |||
git commit -a # 做成一個版本 | git commit -a # 做成一個版本 | ||
+ | |||
+ | |||
+ | |||
git commit -a -m "your message here" | git commit -a -m "your message here" | ||
+ | |||
+ | |||
+ | |||
git add mine.txt | git add mine.txt | ||
+ | |||
+ | |||
+ | |||
git tag v0.02 # 本版別名取為 v0.02 | git tag v0.02 # 本版別名取為 v0.02 | ||
+ | |||
+ | |||
+ | |||
git tag v0.03 40e3e # 把版本 40e3e 取名為 v0.03; | git tag v0.03 40e3e # 把版本 40e3e 取名為 v0.03; | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
git status | git status | ||
+ | |||
+ | |||
+ | |||
git diff # 查詢從上個版本到現在哪幾行被修改 | git diff # 查詢從上個版本到現在哪幾行被修改 | ||
+ | |||
+ | |||
+ | |||
git diff v0.01 v0.03 # 查詢兩個版本間的差異 | git diff v0.01 v0.03 # 查詢兩個版本間的差異 | ||
+ | |||
+ | |||
+ | |||
git diff v0.01: | git diff v0.01: | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
git log # 查詢有史以來哪幾個檔案被修改 | git log # 查詢有史以來哪幾個檔案被修改 | ||
+ | |||
+ | |||
+ | |||
git log -p # 查詢有史以來哪幾行被修改 | git log -p # 查詢有史以來哪幾行被修改 | ||
+ | |||
+ | |||
+ | |||
git log --stat --summary | git log --stat --summary | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
git show v1.01 # 查詢 v1.01 版裡的修改內容 | git show v1.01 # 查詢 v1.01 版裡的修改內容 | ||
+ | |||
+ | |||
+ | |||
git show v1.01: | git show v1.01: | ||
+ | |||
+ | |||
+ | |||
git show v1.01: | git show v1.01: | ||
+ | |||
+ | |||
+ | |||
git show HEAD # 看此版本修改的資料 | git show HEAD # 看此版本修改的資料 | ||
+ | |||
+ | |||
+ | |||
git show HEAD^ # 看此版本前一版的修改的資料 | git show HEAD^ # 看此版本前一版的修改的資料 | ||
+ | |||
+ | |||
+ | |||
git show HEAD^^ | git show HEAD^^ | ||
+ | |||
+ | |||
+ | |||
git show HEAD~4 | git show HEAD~4 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
git grep " | git grep " | ||
+ | |||
+ | |||
+ | |||
git grep " | git grep " | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
git branch 加英文版 | git branch 加英文版 | ||
+ | |||
+ | |||
+ | |||
git branch | git branch | ||
+ | |||
+ | |||
+ | |||
git branch beta v0.5 # 依照 " | git branch beta v0.5 # 依照 " | ||
+ | |||
+ | |||
+ | |||
git checkout 加英文版 | git checkout 加英文版 | ||
+ | |||
+ | |||
+ | |||
git checkout master | git checkout master | ||
+ | |||
+ | |||
+ | |||
git branch -d 加英文版 # 刪除 " | git branch -d 加英文版 # 刪除 " | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
gitk # 版本瀏覽軟體 | gitk # 版本瀏覽軟體 | ||
+ | |||
+ | |||
+ | |||
git gui # 瀏覽從上一版本到現在變動的地方; | git gui # 瀏覽從上一版本到現在變動的地方; | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
git gc # 維護 Git 的資料庫 | git gc # 維護 Git 的資料庫 | ||
+ | |||
+ | |||
+ | |||
git fsck --full | git fsck --full | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
</ | </ | ||
Line 54: | Line 207: | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | |||
+ | git reset --soft HEAD^ # | ||
+ | |||
+ | |||
+ | |||
+ | git push -f origin master# | ||
+ | |||
+ | |||
+ | |||
+ | #! [rejected] | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | git branch test tag# | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Github教程(转载) ===== | ||
+ | |||
+ | |||
+ | |||
+ | - http:// | ||
+ | |||
+ | |||
+ | |||
+ | - http:// | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== 创建和合并分支 ==== | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | |||
+ | #git branch 显示当前分支是master | ||
+ | |||
+ | |||
+ | |||
+ | #git branch new-feature | ||
+ | |||
+ | |||
+ | |||
+ | # git checkout new-feature 切换到新分支 | ||
+ | |||
+ | |||
+ | |||
+ | # vi page_cache.inc.php | ||
+ | |||
+ | |||
+ | |||
+ | # git add page_cache.inc.php | ||
+ | |||
+ | |||
+ | |||
+ | Commit 到本地GIT | ||
+ | |||
+ | |||
+ | |||
+ | # git commit -a -m "added initial version of page cache" | ||
+ | |||
+ | |||
+ | |||
+ | 合并到远程服务器 | ||
+ | |||
+ | |||
+ | |||
+ | # git push origin new-feature | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | 如果new-feature分支成熟了,� | ||
+ | ��得有必要合并进master | ||
+ | |||
+ | |||
+ | |||
+ | #git checkout master | ||
+ | |||
+ | |||
+ | |||
+ | #git merge new-feature | ||
+ | |||
+ | |||
+ | |||
+ | #git branch | ||
+ | |||
+ | |||
+ | |||
+ | #git push | ||
+ | |||
+ | |||
+ | |||
+ | 则master中也合并了new-feature 的代码 | ||
+ | |||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ==== 通过tag创建Branch, | ||
+ | |||
+ | git tag v1.0.0 2c1b73235f77e6204e0b584cfae692486ccf3e92 | ||
+ | |||
+ | git branch leili-v1.0.0 v1.0.0 | ||
+ | |||
+ | git checkout leili-v1.0.0 | ||
+ | |||
+ | git push origin leili-v1.0.0 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== 删除服务器branch ==== | ||
+ | git push origin | ||
+ | |||
+ | ==== git checkout remote branch ==== | ||
+ | Check the remote branch list | ||
+ | git branch -rv | ||
+ | Then create a local branch from the remote branch | ||
+ | git checkout -b test origin/test | ||
+ | | ||
+ | Commit to a remote branch: | ||
+ | git push origin proguard | ||
+ | | ||
+ | Reference: | ||
+ | | ||
+ | ==== git add local to the remote | ||
+ | < | ||
+ | git init | ||
+ | git remote add origin https:// | ||
+ | git status | ||
+ | git pull | ||
+ | git pull origin master | ||
+ | git status | ||
+ | git add . | ||
+ | git commit -m "init commit" | ||
+ | git push origin master | ||
+ | </ | ||
+ | |||
+ | ==== change url ==== | ||
+ | git remote set-url origin https:// | ||
+ | |||
+ | ==== create patch ==== | ||
+ | |||
+ | git show 3514997d38509ab5492e32afc3e4e872daf7932e > | ||
+ | patch -p1 < | ||
+ | | ||
+ | Or you can create patch between two commitid | ||
+ | git diff old-commitid new-commitid > | ||
+ | git diff 557393295b0811278de4875d5fc5558988371bca 0abea5c74c10b81672817aa93ae21cc4852b7702 > | ||
+ | | ||
+ | If you want to revert your patch -R | ||
+ | patch -R -p1 < | ||
+ | | ||
+ | |||
+ | ==== git auto-complete ==== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | wget https:// | ||
+ | sudo vim /etc/bashrc | ||
+ | source / | ||
+ | | ||
+ | ==== git alias ==== | ||
+ | | ||
+ | http:// | ||
+ | | ||
+ | <code BASH> | ||
+ | git config --global alias.co checkout | ||
+ | git config --global alias.br branch | ||
+ | git config --global alias.ci commit | ||
+ | git config --global alias.st status | ||
+ | git config --global alias.visual ' | ||
+ | </ | ||
+ | |||
+ | ==== git tag ==== | ||
+ | |||
+ | < | ||
+ | git tag release/ | ||
+ | git tag -l | ||
+ | git push origin tag release/ | ||
+ | </ | ||
+ | |||
+ | ==== git checkout tag ==== | ||
+ | First make sure that the tag exists locally by doing | ||
+ | |||
+ | git fetch --tags | ||
+ | Then check out the tag by running | ||
+ | git checkout tags/< | ||
+ | | ||
+ | Then create new branch base on the current commitment | ||
+ | git branch newtagbranch | ||
+ | | ||
+ | ==== git fetch & git merge ==== | ||
+ | |||
+ | Refer to | ||
+ | - http:// | ||
+ | - http:// | ||
+ | - http:// | ||
+ | |||
+ | < | ||
+ | git checkout feature/ | ||
+ | git fetch origin feature/ | ||
+ | git diff tmp | ||
+ | git merge tmp | ||
+ | |||
+ | git checkout feature/ | ||
+ | git fetch --all | ||
+ | git fetch origin feature/ | ||
+ | git diff feature/ | ||
+ | git merge origin/ | ||
+ | |||
+ | git branch -D tmp | ||
+ | |||
+ | git checkout feature/ | ||
+ | git fetch origin feature/ | ||
+ | git checkout -b newBrach origin/ | ||
+ | |||
+ | #Delete the local branch that already deleted from the remote | ||
+ | git remote prune origin | ||
+ | |||
+ | #Remote server | ||
+ | git remote -v | ||
+ | |||
+ | #Remote branch | ||
+ | git branch -r | ||
+ | #All branch | ||
+ | git branch -a | ||
+ | |||
+ | #Show the remote repo information | ||
+ | git remote show origin | ||
+ | git remote prune origin | ||
+ | </ | ||
+ | |||
+ | ==== git subtree ==== | ||
+ | Refer to | ||
+ | http:// | ||
+ | <code bash> | ||
+ | git remote add -f datalayer | ||
+ | git subtree add --prefix=datalayer datalayer integration_lean --squash | ||
+ | git fetch all --prune | ||
+ | git fetch datalayer integration_lean | ||
+ | git subtree pull --prefix=datalayer/ | ||
+ | git subtree push --prefix=datalayer/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== git checkout specified file from another branch ==== | ||
+ | |||
+ | * http:// | ||
+ | |||
+ | git checkout branch_name -- path/ | ||
+ | | ||
/var/www/dokuwiki/wiki/data/pages/work/git-guide.txt · Last modified: 2018/02/05 19:15 by percy