GIT基础命令
1. 把一个目录初始化为版本仓库
[root@localhost git_data]# git init
2. 查看当前仓库的状态
[root@localhost git_data]# git status
3. 添加文件到暂存区
# 添加文件file到暂存区
[root@localhost git_data]# git add file
# 添加当前所有的文件到暂存区
方法一:
[root@localhost git_data]# git add *
方法二:
[root@localhost git_data]# git add .
4. 把文件file从暂存区撤走
[root@localhost git_data]# git rm --cached file
5. 同时删除工作目录和暂存区的文件file
[root@localhost git_data]# git rm -f file
6. 把暂存区的文件file添加到本地仓库
# git commit -m "提示信息" file --单个文件
[root@localhost git_data]# git commit -m "add new file" file
# 所有暂存区文件都添加到本地仓库
[root@localhost git_data]# git commit -m "add new file"
7. 重命名文件名称
[root@localhost git_data]# git mv file newfile
8. 对比文件区别
# 对比暂存区与工作目录的区别
[root@localhost git_data]# git diff
# 对比暂存区与本地仓库的区别
[root@localhost git_data]# git diff --cached
9. 某个文件已经被仓库管理,如果更改了文件,只需一条命令即可提交到仓库
[root@localhost git_data]# git commit -am "add newfile"
10. 查看git历史记录
#
[root@localhost git_data]# git log
# 一行显示commit信息
[root@localhost git_data]# git log --onelind
# 查看当前的指针指向
[root@localhost git_data]# git log --oneline --decorate
# 查看具体内容的改动
[root@localhost git_data]# git log -p
# 查看近n次的记录
[root@localhost git_data]# git log -n
11. 查看历史总记录
[root@localhost git_data]# git reflog
12. 回滚数据到某一个commit
[root@localhost git_data]# git reset --hard 3d4062f
3d4062f -- 索引
GIT分支
1. 查看分支/当前分支
[root@localhost git_data]# git branch
2. 创建分支
[root@localhost git_data]# git branch 分支名称
3. 切换分支
#
[root@localhost git_data]# git checkout 分支名称
# 创建并切换到新的分支
[root@localhost git_data]# git checkout -b 分支名称
4. 删除分支
[root@localhost git_data]# git branch -d 分支名称
5. 合并分支(需在master上执行)
#
[root@localhost git_data]# git merge 分支名称
# 若两个分支有冲突需手动操作
修改前:
<<<<<<< HEAD
b1
=======
b2
>>>>>>> test
修改后:
b1
b2
标签使用
1. 打标签
# 对当前打标签
[root@localhost git_data]# git tag -a v3.0 -m "tag v3.0"
-m -- 文字说明
-a -- 添加
# 对某一次commit打标签
[root@localhost git_data]# git tag -a v1.0 bcb79c0 -m "tag v1.0"
bcb79c0 -- 哈希值
- 查看所有标签
[root@localhost git_data]# git tag
- 查看标签信息
[root@localhost git_data]# git show 标签名称
- 删除标签
[root@localhost git_data]# git tag -d 标签名字
远程仓库
1. 删除远程仓库
[root@localhost git_data]# git remote remove origin
2. 增加远程仓库
[root@localhost git_data]# git remote add origin git@172.16.1.10:test/git.git
网友评论