git使用说明:
1. 设置git用户名和邮箱信息
git config --global user.name "name"
git config --global user.email "name@xxx.com"
2. 建立本地仓库
git init
git add .
git commit
3. 查看log和diff
git diff -cached
git diff
git status
git log
4. clone git
git clone ssh://name@xx.xx.xx.xx/test
5. 管理远程仓库
git remote add origin ssh://name@xx.xx.xx.xx/test
git push origin master
git remote -v
git remote
git remote rm origin
git remote rename
6. 版本管理
git add file_name
git commit
git reset --soft 只撤销commit,保留working tree和index file。
git reset --hard 撤销commit、index file和working tree,即撤销销毁最近一次的commit
git reset --mixed 撤销commit和index file,保留working tree
git reset和git reset --mixed完全一样
git reset -- 用于删除登记在index file里的某个文件。
git reflog -- 看以前所有的log
git reset --hard a745d31b9c0017bf277c8dd2961b180f6d75f617 -- 到commit号a745处
7. 分支管理
git branch branch_name
git branch -- list branch
git branch -d branch_name -- delete a merged branch
git branch -D branch_name -- delete a branch
git checkout branch_name -- switch to branch
git checkout master -- switch to master
git merge branch_name
git tag V3 5b888 //以后可以用V3来代替复杂的名称(5b888…)
git show V3
git branch stable V3 //建立一个基于V3的分支
8. 建立bare仓库
现在test目录下建立仓库
git init
从仓库建立bare仓库
git clone --bare test test.git
bare仓库可以push和pull
实例:
git clone --bare test test.git
git clone ssh://name@xx.xx.xx.xx/test/xxx.git