您的位置:首页 > 其它

常用git操作

2013-12-15 15:28 281 查看
常用git操作

git add/rm

git add <file>                 将文件加入index file

git rm [--cached]                删除,加--cached表示仅从index file中删除文件,即放弃跟踪.



git diff

git diff --cached/--staged          当前索引与上次提交(有哪些需要commit)

git diff HEAD[^]               工作目录与上次提交(当前目录与上次提交有何改变)

git diff HEAD~2      与前二次commit 之间的区别

git  commit 

git
 commit [-a] -m <msg>           跳过add, 提交目录下所有修改过的文件

git commit [-I] filename                                       跳过add,提交修改过的某个文件

git commit --amend [-m <msg>]       修复上次提交

git reset

git reset --hard HEAD[^]           将 working tree 和 index file 都撤销到以前状态。(撤销commit动作、add动作、对文件的修改)

git reset --mixed HEAD[^]         
 撤销 commit 和index file,只保留 working tree 的信息 (撤销commit动作、add动作)

git reset --soft HEAD[^]            只撤销 commit,对文件的修改依然保留,此时用git status可以看到对文件的修改状态。

git remote

git remote [-v]                    显示远程仓库,加-v选项可显示仓库地址

git remote add <repo_name> <url>         添加远程仓库,repo_name为shortname,指代仓库地址

git remote rename <old_name> <new_name>    更名

git remote rm <repo_name>            删除远程仓库

git remote show <repo_name>          查看远程仓库信息

git remote fetch <repo_name>           从远程仓库抓取数据(并不合并)

git pull/push/fetch

git pull    <repo_name> <branch_name>      拉去数据并合并到当前分支

git push <repo_name> <branch_name>      推送指定分支到指定仓库

git fetch <repo_name> <branch_name>[:<local_branch_name>]    拉去数据,未合并

git gc                     用垃圾回收机制清除由于 reset 而造成的垃圾代码

git status                  显示当前工作目录状态

git log [-p]                   显示提交历史(many useful options to be learned)

git branch [branch]               显示/新建分支

git branch -d/-D               删除分支(d表示“在分支合并后删除分支”,D表示无论如何都删除分支)

git show-branch

git checkout <branch>            切换分支(分支未commit无法切换)

git merge <branch>              合并分支

git merge == git pull .

git show <branch | commit | tag | etc>        显示对应对象的信息

git grep <rep> [object]             (在指定对象(历史记录)中)搜索        

git cat-file                    查看数据

git cat-file <-t | -s | -e | -p | (type)> <object>        type can be one of: blob, tree, commit, tag

git ls-files [--stage]              show information about files in the index and the working tree(实际是查看索引文件)

git watchchanged <since>..<until>       显示两个commit(当然也可以是branch)的区别
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git