基本操作

1
2
3
4
5
6
7
8
9
10
11
git init # 新建git仓库
git add <filename/directory/.> # 将工作区的文件、目录、所有文件添加到stage
git commit -m "commit" # 将stage的文件添加到版本库中
git commit -am "commit" # 上两步合二为一
git commit -a # 更加简化
git status # 查看git状态
git log # 查看提交日志
git log 5 --pretty=oneline # 方便查看日志
git diff # 查看区别
git rm filename # 删除文件
git ls-files # 查看本地仓库文件

版本控制

1
2
3
4
5
6
7
git reset HEAD # 将stage中的文件清空(撤销git add操作)
git reset --hard HEAD^^ # 所有区域回退到上上个版本 取决于^的数量
git reset --hard HEAD~1 # 回退一个版本
git reset --hard 标识符 # 回退到某个版本,输入5位+,不重复即可
git reflog # 查看之前的引用位置,防止无法回滚

git checkout --filename #恢复已提交的误删除工作区的文件

远程仓库

1
2
3
4
5
6
7
8
9
10
git clone url # 下载远程仓库项目
git push origin branch # 推送本地分支到远程
git push origin :remote_branch # 删除远程分支
git checkout -b local_branch origin/remote_branch # 拉取远程指定分支并在本地创建分支
git fetch # 获取分支
git pull # 拉取最新内容

'''多人协作'''
# 提交前先pull

分支

1
2
3
4
5
6
git checkout branch # 切换到指定分支
git checkout -b new_branch # 新建分支并切换到新建分支
git branch -d branch # 删除指定分支
git branch # 查看所有分支 *代表目前分支
git branch -m oldBranch newBranch 重命名分支
git branch -a # 查看本地和远程分支

标签Release 发行版

1
2
3
4
5
6
git tag tagName # 新建标签 默认为HEAD
git tage -a tag_name -m 'xx' # 添加标签并指定描述信息
git tag # 查看所有标签
git tag -d tag_name # 删除本地标签
git push origin tag_name # 推送本地标签到远程

Idea

  • 下载插件.ignore