最权威的Git书籍 http://git-scm.com/book/zh
##Git常用技巧
###创建本地项目
1 2 3
| git init git add README.txt git commit -m 'init project'
|
###提交到Remote仓库
git remote add origin https://github.com/wecoders/testproject.git
git push -u origin master #提交到master分支(默认为主干)
这里的origin是可以随便定义的,比如定义为mygithub-project
git remote add mygithub-project https://github.com/wecoders/testproject.git
这样远程名mygithub-project就是代表https://github.com/wecoders/testproject.git
###恢复本地被删除的文件
直接使用checkout指令
git checkout src/test.java
或者可以批量恢复被删除的文件
git ls-files -d | xargs git checkout
###根据commits生成patch补丁
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git log | grep ^commit | head -10 #列出最近10条commit commit 88093868a6a02c0cf5012465a674c360502ffd0d commit e7f11a1fd210c70a4fc1ffb66e85c40e6275aa88 commit 5d754c56cad45a586d1fb44380c760e925f6e9a4 commit 23a92f158d4829e6f10b193913c28ad43997c6ed commit ed7b6a1067a38ff58f47017d18838d97a9f49086 commit dfedbb074ac30546bc984f5d05d64ab16d0be3d9 commit 369f714f1916c4d390defa22b86b8971b4b6c00d commit 2fa5f2b86709256e75b62bb03c070e9a967a958b commit ebe53e01a5b98bd830a5515c110334aa715b2873 commit 665739e4d7cc439d4198a80852bb19838a32fc1d git format-patch 665739e4d7cc439d4198a80852bb19838a32fc1d #根据665739e4...生成patch
|
###先checkout某个commit,并据此commit创建分支
1
| git checkout -b branch_test1 665739e4d7cc439d4198a80852bb19838a32fc1d
|