基本操作
创建一个裸仓库
git init --bare
初始化基本仓库
git init
配置作者信息
|
|
添加文件到暂存区(跟踪文件)
git add [filename]
git add *
// 跟踪所有已跟踪过又修改的文件
移除文件
git rm [filename]
重命名一个文件
git mv [oldname] [newname]
提交暂存区
git commit -m "description information"
// git commmit 只提交在暂存区的内容
git commit -a -m "description information"
// 将跟踪过又修改的为放入暂存跟踪后直接提交,已放入暂存区的也直接一起提交
查看工作目录的状态
git status
查看提交历史记录
git log
查看文件改变
git diff
//默认比较工作区下的文件与最近一次提交的不同
git diff -- stash
//比较暂存区下的文件与最近一次提交的不同
撤销操作
撤销加入暂存区的操作
git reset -- [filename]
撤销修改的操作
git checkout -- [filename]
将本地的修改放进回收站
git stash
从回收站中恢复本地的修改
git stash apply
Tag操作
查看tag
git tag
创建tag
git tag -a tagname -m "tag description information"
显示tag信息
git show tagname
对之前的提交打tag
git tag -a tagname -m "tag description information" commit-num
分支操作
查看分支
// 默认查看本地分支
git branch
// 查看本地以及远端分支
git branch -a
// 查看远端分支
git branch -r
创建分支
git branch newbranchname
删除分支
git branch -d/D branchname
切换分支
git checkout branchname
创建分支并切换到新建的分支下
git branch checkout -b newbranch
合并分支
git merge branchname branchname
rebase操作
git rebase branchname branchname
远端仓库操作
克隆一个远端仓库
git clone URL/repodirectory
添加远端仓库
git remote add reponame URL/repodirectory
更新远端仓库的分支和数据
git fetch
//默认更新远端master分支
git fetch reponame branchname
//更新指定远端的分支
获取并合并远端仓库的分支到当前分支
git pull reponame branchname
eg: git pull origin master
上传本地分支和数据到远端仓库
git push reponame branchname
eg: git push origin master
跟踪远端仓库上的分支
git checkout —track origin/testbranch
git checkout -b test origin/testbranch