在ubuntu中使用git流程

本文介绍了如何使用Git进行基本操作,包括创建仓库、查看状态、添加和提交文件、撤销更改以及查看提交历史。重点展示了gitinit、gitstatus、gitadd、gitcommit和gitlog/gitshow的命令及其用途。
摘要由CSDN通过智能技术生成
  1. git init 创建git 仓库
    cd 到目标文件夹,输入git init,生成一个.git文件夹
    在这里插入图片描述

  2. git status 查看是否有需要待提交的代码或者文件

bobo@ubuntu:~/prectice/studyLinux$ git status 
位于分支 master
无文件要提交,干净的工作区
bobo@ubuntu:~/prectice/studyLinux$ git status
位于分支 master
尚未暂存以备提交的变更:
  (使用 "git add <文件>..." 更新要提交的内容)
  (使用 "git restore <文件>..." 丢弃工作区的改动)
	修改:     MultipleThread/MyThread.cpp

修改尚未加入提交(使用 "git add" 和/或 "git commit -a"
  1. git add 选择需要提交的文件
bobo@ubuntu:~/prectice/studyLinux$ git add .    #git add .    选中所有待提交文件
bobo@ubuntu:~/prectice/studyLinux$ git status
位于分支 master
要提交的变更:
  (使用 "git restore --staged <文件>..." 以取消暂存)
	修改:     MultipleThread/MyThread.cpp

  1. git commit 提交文件
bobo@ubuntu:~/prectice/studyLinux$ git commit -m "测试2"  #-m "测试2"  提交注释
[master 762f6f0] 测试2
 1 file changed, 1 insertion(+), 1 deletion(-)
bobo@ubuntu:~/prectice/studyLinux$ git status 
位于分支 master
无文件要提交,干净的工作区
bobo@ubuntu:~/prectice/studyLinux$ 
  1. git show 显示文件
    需要与git log 配合使用
    我们首先,使用 git log 命令,查看 git 的提交日志列表,具体命令如下:

git log

执行完毕后,如下图所示:

bobo@ubuntu:~/prectice/studyLinux$ git log
commit 762f6f059872e2bd0c034909e9cfd33d16e97323 (HEAD -> master)
Author: bobo <2307460652@qq.com>
Date:   Sat Mar 9 18:02:29 2024 -0800

    测试2

commit d4f808d7a468478cc007e718e565894bcd6a1593
Author: bobo <2307460652@qq.com>
Date:   Sat Mar 9 17:24:11 2024 -0800

    测试

commit 07d1e331f14c2152ef3446c2168f4e7d416d83c3
Author: bobo <2307460652@qq.com>
Date:   Sat Mar 9 17:17:07 2024 -0800

    单个线程测试

commit 2883ef1103b320715f018fcc1432f5e1bf0a5638
Author: bobo <2307460652@qq.com>
Date:   Sat Mar 9 16:35:00 2024 -0800

    建立版本管理

现在,我们使用 git show 命令,查看某次提交某个文件的修改详情,具体命令如下:

git show d4f808d7 MultipleThread/MyThread.cpp
注意:d4f808d7就是从git log 中的某一ID
执行完毕后,如下图所示:
在这里插入图片描述

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值