git

  1.安装git

1
2
3
4
#linux版
[root@localhost ~]# yum install git -y
#windowns版
https://github.com/git-for-windows/git/releases/download/v2.25.1.windows.1/Git-2.25.1-64-bit.exe
  2.配置git(会在当前用户的家目录下创建一个.gitconfig文件)
1
2
3
4
5
6
7
8
9
10
11
12
#配置用户名
[root@localhost ~]# git config --global user.name "lee"  
#配置用户邮箱
[root@localhost ~]# git config --global user.email "lee@example.com"
[root@localhost ~]# git config --global color.ui true
 
[root@localhost ~]# cat .gitconfig
[user]
    name = lee
    email = lee@example.com
[color]
    ui = true

  3.创建本地仓库

1
2
3
4
[root@localhost ~]# mkdir demo
[root@localhost ~]# cd demo/
[root@localhost demo]# git init
初始化空的 Git 版本库于 /root/demo/.git/

  

 

  • git常用命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
add        #添加文件到暂存区
bisect     通过二分查找定位引入 bug 的变更
branch     列出、创建或删除分支
checkout   检出一个分支或路径到工作区
clone      克隆一个版本库到一个新目录
commit     #提交信息到版本库
diff       显示提交之间、提交和工作区之间等的差异
fetch      从另外一个版本库下载对象和引用
grep       输出和模式匹配的行
init       创建一个空的 Git 版本库或重新初始化一个已存在的版本库
log        显示提交日志
merge      合并两个或更多开发历史
mv         #移动或重命名一个文件、目录或符号链接
pull       获取并合并另外的版本库或一个本地分支
push       更新远程引用和相关的对象
rebase     本地提交转移至更新后的上游分支中
reset      重置当前HEAD到指定状态
rm         从工作区和索引中删除文件
show       显示各种类型的对象
status     显示工作区状态
tag        创建、列出、删除或校验一个GPG签名的 tag 对象
  • 创建文件比提交到暂存区
1
2
[root@localhost demo]# touch file1 file2 file3
[root@localhost demo]# git add .
  • 将暂存区文件提交到仓库
1
2
3
4
5
6
[root@localhost demo]# git commit -m "新增file1-3"
[master(根提交) aa040d5] 新增file1-3
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file1
create mode 100644 file2
create mode 100644 file3
  • 更改文件名称
1
[root@localhost demo]# git mv file1 file4
  • 本地目录文件和暂存区文件比对
1
[root@localhost demo]# git diff file4
  • 暂存区文件和本地仓库文件比对
1
[root@localhost demo]# git diff --cached file4

  • 文件回退

  • 查看git提交日志
1
2
3
4
5
6
7
8
9
10
#查看所有改动,以一行显示
[root@localhost demo]# git log --oneline
8097089 新改动
aa040d5 新增file1-3
 
#查看最近一次的改动
[root@localhost demo]# git log -1
 
#查看最近两次改动
[root@localhost demo]# git log -2
  • 分支
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#查看分支
[root@localhost demo]# git branch
 
#创建分支
[root@localhost demo]# git branch 分支名
 
#切换分支
[root@localhost demo]# git checkout 分支名
 
#删除分支,需要先退出当前分支
[root@localhost demo]# git branch -d 分支名
 
#合并分支
[root@localhost demo]# git checkout master
[root@localhost demo]# git merge 被合并的分支名
  • 标签
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#查看所有标签
[root@localhost demo]# git tag
 
#查看标签详细信息
[root@localhost demo]# git show v1.0
 
#对当前最新代码打标签
[root@localhost demo]# git tag -a "v1.0" -m "描述信息"
 
#指定commitID打标签
[root@localhost demo]# git tag -a "v1.0" 42db8caa -m "描述信息"
 
#删除标签
[root@localhost demo]# git tag -d v1.0

  

  

posted @   ForLivetoLearn  阅读(202)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
点击右上角即可分享
微信分享提示