work:git-guide
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
work:git-guide [2011/09/10 18:14] – external edit 127.0.0.1 | work:git-guide [2018/02/05 19:15] (current) – [git checkout specified file from another branch] 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 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
< | < | ||
+ | |||
+ | |||
+ | |||
git reset --soft HEAD^ # | git reset --soft HEAD^ # | ||
+ | |||
+ | |||
+ | |||
git push -f origin master# | git push -f origin master# | ||
+ | |||
+ | |||
+ | |||
#! [rejected] | #! [rejected] | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
git branch test tag# | git branch test tag# | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
===== Github教程(转载) ===== | ===== Github教程(转载) ===== | ||
+ | |||
+ | |||
+ | |||
- http:// | - http:// | ||
+ | |||
+ | |||
+ | |||
- http:// | - http:// | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
==== 创建和合并分支 ==== | ==== 创建和合并分支 ==== | ||
+ | |||
+ | |||
+ | |||
< | < | ||
+ | |||
+ | |||
+ | |||
#git branch 显示当前分支是master | #git branch 显示当前分支是master | ||
+ | |||
+ | |||
+ | |||
#git branch new-feature | #git branch new-feature | ||
+ | |||
+ | |||
+ | |||
# git checkout new-feature 切换到新分支 | # git checkout new-feature 切换到新分支 | ||
+ | |||
+ | |||
+ | |||
# vi page_cache.inc.php | # vi page_cache.inc.php | ||
+ | |||
+ | |||
+ | |||
# git add page_cache.inc.php | # git add page_cache.inc.php | ||
+ | |||
+ | |||
+ | |||
Commit 到本地GIT | Commit 到本地GIT | ||
+ | |||
+ | |||
+ | |||
# git commit -a -m "added initial version of page cache" | # git commit -a -m "added initial version of page cache" | ||
+ | |||
+ | |||
+ | |||
合并到远程服务器 | 合并到远程服务器 | ||
+ | |||
+ | |||
+ | |||
# git push origin new-feature | # git push origin new-feature | ||
- | 如果new-feature分支成熟了,觉得有必要合并进master | + | |
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | 如果new-feature分支成熟了,� | ||
+ | ��得有必要合并进master | ||
+ | |||
+ | |||
#git checkout master | #git checkout master | ||
+ | |||
+ | |||
+ | |||
#git merge new-feature | #git merge new-feature | ||
+ | |||
+ | |||
+ | |||
#git branch | #git branch | ||
+ | |||
+ | |||
+ | |||
#git push | #git push | ||
+ | |||
+ | |||
+ | |||
则master中也合并了new-feature 的代码 | 则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/ | ||
+ | | ||
+ | ==== git revert ==== | ||
+ | |||
+ | github support revert the pull request, so after you have revert the pull request, and still want to merge the feature branch, then you need to find the revert commit id, and revert it again | ||
+ | |||
+ | git revert ce8731f5cbc55ab50723ee2a8ec615b462b3b0e6 -m 1 | ||
+ | |||
+ | So the full log will be like | ||
+ | < | ||
+ | commit 817947e37c5f835384fd282ab2004a6d9a848975 (HEAD -> pjq/ | ||
+ | Author: Jianqing Peng < | ||
+ | Date: Mon Feb 5 19:09:40 2018 +0800 | ||
+ | |||
+ | Revert "Merge pull request #2087 from sfofficial/ | ||
+ | | ||
+ | This reverts commit ce8731f5cbc55ab50723ee2a8ec615b462b3b0e6, | ||
+ | changes made to 67a513f686ec9c203b7d38a3df1abbe7079320d4. | ||
+ | |||
+ | commit ce8731f5cbc55ab50723ee2a8ec615b462b3b0e6 | ||
+ | Merge: 67a513f686 a157cdef4e | ||
+ | Author: Jianqing Peng < | ||
+ | Date: Mon Feb 5 19:07:33 2018 +0800 | ||
+ | |||
+ | Merge pull request #2087 from sfofficial/ | ||
+ | | ||
+ | Revert "add new feature 1" | ||
+ | |||
+ | commit a157cdef4e391981b2053b52f560a70464b2dd7f | ||
+ | Author: Jianqing Peng < | ||
+ | Date: Mon Feb 5 19:06:29 2018 +0800 | ||
+ | |||
+ | Revert "add new feature 1" | ||
+ | |||
+ | commit 67a513f686ec9c203b7d38a3df1abbe7079320d4 | ||
+ | Merge: 08a5c9c33e a161eed1e3 | ||
+ | Author: Jianqing Peng < | ||
+ | Date: Mon Feb 5 19:05:57 2018 +0800 | ||
+ | |||
+ | Merge pull request #2086 from sfofficial/ | ||
+ | | ||
+ | add new feature 1 | ||
+ | |||
+ | commit a161eed1e3d200f6121690494dd6df1d065163fb (origin/ | ||
+ | Author: Jianqing Peng < | ||
+ | Date: Mon Feb 5 19:05:11 2018 +0800 | ||
+ | |||
+ | add new feature 1 | ||
+ | |||
+ | |||
+ | </ |
/var/www/dokuwiki/wiki/data/attic/work/git-guide.1315649645.txt.gz · Last modified: 2016/05/05 13:06 (external edit)