美文网首页
GIT--基础命令、分支管理及标签使用

GIT--基础命令、分支管理及标签使用

作者: 霸道ki | 来源:发表于2020-02-11 16:15 被阅读0次

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 -- 哈希值
  1. 查看所有标签
[root@localhost git_data]# git tag
  1. 查看标签信息
[root@localhost git_data]# git show 标签名称
  1. 删除标签
[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

相关文章

  • GIT--基础命令、分支管理及标签使用

    GIT基础命令 1. 把一个目录初始化为版本仓库 2. 查看当前仓库的状态 3. 添加文件到暂存区 4. 把文件f...

  • Git命令总结

    基础命令 远程仓库 标签管理 分支管理

  • git 命令

    Git 项目命令文档 基础命令 分支管理 标签管理 搭建Git服务器

  • 【Git】操作指南

    文章记述了通过终端命令行使用git频率较高的一些操作,这些操作包括仓库管理,远程仓库,分支管理,标签管理等。 仓库...

  • HTML学习笔记(二) 之各种标签的使用方法(1)

    一、html 基础标签及使用方法 基础标签使用例子: 二、html 图片标签及使用方法 1.map 标签用于客户端...

  • Android项目基础规范

    参考Android项目基础规范26 Apr 2016代码管理Git 使用 rebase 命令来合并分支,尽量不要直...

  • Git 命令总结

    Git 命令总结 基本命令 远程仓库 分支管理 标签管理 自定义 Git 搭建 Git 服务器 安装 git:$ ...

  • Git 标签管理

    标签管理 创建标签 在Git中打标签需要先切换到需要打标签的分支上: 然后,敲命令 git tag ...

  • Git常用操作速查

    目录 基本操作 分支操作 合并分支,推送保存 回退及撤销 ssh公钥生成及配置 stash暂存现场 tag标签管理...

  • Git分支及标签管理

    添加分支 git branch 切换分支 git checkout 添加分支并切换 g...

网友评论

      本文标题:GIT--基础命令、分支管理及标签使用

      本文链接:https://www.haomeiwen.com/subject/fvpxfhtx.html