User Tools

Site Tools


work:git-guide

This is an old revision of the document!


收集一些git教程和常用命令

git常用命令速查



git init             # 開始用 Git 來管理



git add .            # 把所有檔案加入 Git



git commit -a        # 做成一個版本



git commit -a -m "your message here"  # commit 時直接寫訊息, 不用到下個螢幕上寫



git add mine.txt     # 把 mine.txt 加入管理



git tag v0.02        # 本版別名取為 v0.02



git tag v0.03 40e3e  # 把版本 40e3e 取名為 v0.03;







git status           # 查詢從上個版本到現在哪些檔案被修改



git diff             # 查詢從上個版本到現在哪幾行被修改



git diff v0.01 v0.03 # 查詢兩個版本間的差異



git diff v0.01:story.txt v0.03:story.txt    # 查詢兩個版本間某個檔案的差異







git log     # 查詢有史以來哪幾個檔案被修改



git log -p  # 查詢有史以來哪幾行被修改



git log --stat --summary  # 查詢每個版本間變動的檔案跟行數







git show v1.01            # 查詢 v1.01 版裡的修改內容



git show v1.01:story.txt  # 叫出在 v1.01 版時的 story.txt 檔案



git show v1.01:story.txt > test.txt   # 把 v1.01 版的 story.txt 抓出來,放入一個叫 test.txt 的檔案



git show HEAD             # 看此版本修改的資料



git show HEAD^            # 看此版本前一版的修改的資料



git show HEAD^^           # 看此版本前前一版的修改的資料



git show HEAD~4           # 看此版本前前前前一版的修改的資料 >_<







git grep "貓" v0.01   # 查詢 0.01 版裡頭有沒有貓



git grep "熊"         # 查詢現在的版本裡有沒有熊







git branch 加英文版    # 建立新的分枝叫 "加英文版"



git branch            # 查看現有的分枝



git branch beta v0.5  # 依照 "v0.5" 版裡的內容來建立一個叫 "beta" 的分枝



git checkout 加英文版  # 換到 "加英文版" 的分枝上



git checkout master   # 換到主幹上



git branch -d 加英文版 # 刪除 "加英文版" 分枝







gitk    # 版本瀏覽軟體



git gui # 瀏覽從上一版本到現在變動的地方; 沒辦法顯示中文







git gc                # 維護 Git 的資料庫



git fsck --full       # 同上, 三不五時下次指令








git reset --soft HEAD^ #commit完后,发现有些文件改错了,或者没有add进去,用这个命令可以重新commit,添加comment.



git push -f origin master#当用过reset后,重新commit,往上push的时候,可能会遇到



                            #! [rejected]        master -> master (non-fast-forward),这个时候,如果确定没有冲突的话,可以加-f(force)强制push上去.







git branch test tag#以某个tag生成branch,再用git checkout test,切换到那个branch.






Github教程(转载)

创建和合并分支



#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  :server-branch-name

git checkout remote branch

Check the remote branch list

git branch -r

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:http://stackoverflow.com/questions/1783405/git-checkout-remote-branch

git add local to the remote

git init
git remote add origin https://github.com/pjq/SoundRecordingExample2.git
git status
git pull
git pull origin master
git status
git add .
git commit -m "init commit"
git push origin master

/var/www/dokuwiki/wiki/data/attic/work/git-guide.1368109924.txt.gz · Last modified: 2016/05/05 13:06 (external edit)