原文连接git
github是全球最大的代码托管网站,其中管理项目的git命令更是繁多,因此在此记录一下github
新建一个目录,初始化为git代码库 git init 'project name' 下载一个项目到当前目录下 git clone 'url'
添加指定文件或目录到本地暂存区 git add 'file'或'dir' 添加目录下全部文件到本地暂存区 git add *
从git代码库中移除文件 git rm 'file' 从git代码库中移除目录 git rm -r 'dir'
提交暂存区内容到git代码库 git commit -m 'commit message' 提交暂存区指定文件到git代码库 git commit 'file' -m 'commit message' 提交工做区内容到git代码库(不须要git add) git commit -a 提交一次新信息替换上一次提交(若是没有变化,改写上一次提交信息) git commit --amend -m 'message'
显示有变动的文件 git status 显示暂存区和工做区的区别 git diff 显示当前分支的历史版本信息 git log 根据关键词搜索提交历史信息 git log -S 'keyword' 显示指定文件修改详情 git blame 'file' 显示当前分支的最近几回提交 git reflog
列出全部本地分支 git branch 列出全部远程分支 git branch -r 列出全部本地远程分支 git branch -a 新建一个分支,但保持在当前分支 git branch 'branch name' 删除分支 git branch -d 'branch name'
恢复暂存区的文件到工做区 git checkout 'file' 恢复暂存区的全部文件到工做区 git checkout * 切换到上一个分支 git checkout - 新建一个分支,并切换到该分支 git checkout -b 'branch name'
将分支合并到当前分支 git merge 'branch name'
列出全部标签 git tag 新建一个标签在当前提交 git tag 'tag name' 删除本地标签 git tag -d 'tag name'
显示全部远程git代码库 git remote -v 显示指定远程git代码库信息 git remote show 'remote name'
提交标签到指定远程git代码库 git push 'remote name' 'tag name' 提交分支到指定远程git代码库 git push 'remote name' 'branch name' 强行提交当前分支到远程git代码库 git push 'remote name' -force
帮助信息 git -help