Git常用命令
walkman 2024/3/7 Git
# Git常用命令
# 创建仓库
- git init:初始化一个git仓库
git init
1
- git clone:clone一个git仓库
git clone git://github.com/schacon/grit.git
1
# 基本指令
- git config:配置信息
git config --global user.name '你的用户名'
git config --global user.email '你的邮箱'
1
2
2
- git add:添加文件到缓存命令
git add .
git add *.java
1
2
3
2
3
- git status:查看文件的状态命令
git status
1
- git diff:查看更新的详细信息命令
- 尚未缓存的改动:git diff
- 查看已缓存的改动: git diff --cached
- 查看已缓存的与未缓存的所有改动:git diff HEAD
- 显示摘要而非整个 diff:git diff --stat
- git commit:提交命令
git commit -m "第一次版本提交"
# 如果你觉得 每次 commit之前要add一下,想跳过add这一步,可以直接使用 -a选项,如:
git commit -am "第一次版本提交"
1
2
3
4
2
3
4
- git reset HEAD:取消缓存命令
git reset HEAD test.txt
1
- git rm:删除命令
# 简单地从工作目录中手工删除文件
git rm <file>
# 如果删除之前修改过并且已经放到暂存区域的话,则必须要用强制删除选项 -f
git rm -f <file>
# 如果把文件从暂存区域移除,但仍然希望保留在当前工作目录中,换句话说,仅是从跟踪清单中删除,使用 --cached 选项即可
git rm --cached <file>
# 可以递归删除,即如果后面跟的是一个目录做为参数,则会递归删除整个目录中的所有子目录和文件:
git rm –r *
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- git mv:移动或重命名命令
git mv test.txt newtest.txt
1
# Git分支管理
- git branch:查看分支命令
- git branch (branchname):创建分支命令
- git checkout (branchname):切换分支命令
- git merge:合并分支命令
- git branch -d (branchname):删除分支命令
# Git查看提交历史
git log
–oneline :查看历史记录的简洁版本 –graph :查看历史中什么时候出现了分支、合并 –reverse :逆向显示所有日志 –author :查找指定用户的提交日志 –since、–before、 --until、–after: 指定帅选日期 –no-merges :选项以隐藏合并提交
# Git 远程仓库
- git remote add:添加远程仓库
git remote add [alias] [url]
1
- git remote:查看当前的远程仓库
- git fetch、git pull:提取远程仓仓库
- git push:推送到远程仓库
- git remote rm:删除远程仓库