当前位置: 首页 > news >正文

修改⽂件之git

修改⽂件

Git ⽐其他版本控制系统设计得优秀,因为 Git 跟踪并管理的是修改,⽽⾮⽂件。

什么是修改?⽐如你新增了⼀⾏,这就是⼀个修改,删除了⼀⾏,也是⼀个修改,更改了某些字符,也是⼀个修改,删了⼀些⼜加了⼀些,也是⼀个修改,甚⾄创建⼀个新⽂件,也算⼀个修改。

让我们将 ReadMe ⽂件进⾏⼀次修改:

hyb@139-159-150-152:~/gitcode$ cat ReadMe 
hello bit
hello git
hello world

此时,仓库中的 ReadMe 和我们⼯作区的 ReadMe 是不同的,如何查看当前仓库的状态呢? git status 命令⽤于查看在你上次提交之后是否有对⽂件进⾏再次修改。

1 hyb@139-159-150-152:~/gitcode$ git status
2 On branch master
3 Changes not staged for commit:
4 (use "git add <file>..." to update what will be committed)
5 (use "git restore <file>..." to discard changes in working directory)
6 modified: ReadMe
7
8 no changes added to commit (use "git add" and/or "git commit -a")

上⾯的结果告诉我们,ReadMe 被修改过了,但还没有完成添加与提交。

⽬前,我们只知道⽂件被修改了,如果能知道具体哪些地⽅被修改了,就更好了。有同学会说,我刚改的我知道呀!可是,你还记得你三天前写了什么代码吗?或者没写?

1 hyb@139-159-150-152:~/gitcode$ git diff ReadMe
2 diff --git a/ReadMe b/ReadMe
3 index 9c9e1f0..4a97140 100644
4 --- a/ReadMe
5 +++ b/ReadMe
6 @@ -1,2 +1,3 @@
7 hello bit
8 -hello bit
9 +hello git
10 +hello world

git diff [file] 命令⽤来显⽰暂存区和⼯作区⽂件的差异,显⽰的格式正是Unix通⽤的diff格式。也可以使⽤ git diff HEAD – [file] 命令来查看版本库和⼯作区⽂件的区别。

知道了对 ReadMe 做了什么修改后,再把它提交到本地仓库就放⼼多了。

1 hyb@139-159-150-152:~/gitcode$ git add ReadMe
2 hyb@139-159-150-152:~/gitcode$ git status
3 On branch master
4 Changes to be committed:
5 (use "git restore --staged <file>..." to unstage)
6 modified: ReadMe

git add 之后,就没有看到上⾯ no changes added to commit (use “git add” and/or “git commit -a”) 的消息了。接下来让我们继续 git commit 即可:

hyb@139-159-150-152:~/gitcode$ git commit -m "add modify ReadMe file"
[master 94da695] add modify ReadMe file1 file changed, 2 insertions(+), 1 deletion(-)
hyb@139-159-150-152:~/gitcode$ git status
On branch master
nothing to commit, working tree clean
http://www.dtcms.com/a/364061.html

相关文章:

  • 企业微信AI在银行落地的3个实用场景:智能机器人、搜索、文档的具体用法
  • 了解名词ARM Linux的SOC
  • 枚举和泛型
  • 高性能接口实现方案
  • 刷题日记0902
  • 38.Ansible判断+实例
  • 硬件:51单片机
  • 【Unity Shader学习笔记】(一)计算机图形学
  • shell脚本案例
  • 【Unity Shader学习笔记】(二)图形显示系统
  • nmap扫描端口,netstat
  • 二叉树经典题目详解(下)
  • CH01-1.1 Exercise-Ordinary Differential Equation-by LiuChao
  • 猫猫狐狐的“你今天有点怪怪的”侦察日记
  • 标贝科技参编《数据标注产业发展研究报告(2025 年)》
  • ARM裸机开发(GPIO标准库开发)
  • Java搭建高效后端,Vue打造友好前端,联合构建电子采购管理系统,实现采购流程电子化、自动化,涵盖采购全周期管理,功能完备,附详细可运行源码
  • 提高卷积神经网络模型的一些应用
  • 复刻 Python 实现的小智语音客户端项目py-xiaozhi日记
  • AI助力开发:JetBrains官方DeepSeek插件Continue一站式上手!
  • 为什么研发文档的变更缺乏审批和追溯
  • 2025 大学生职业准备清单:从数据到财会,这些核心证书值得考
  • 毕业项目推荐:70-基于yolov8/yolov5/yolo11的苹果成熟度检测识别系统(Python+卷积神经网络)
  • Spring 循环依赖问题
  • 【代码随想录day 22】 力扣 40.组合总和II
  • 威科夫与强化学习状态
  • Spring Security 如何使用@PreAuthorize注解
  • srm信息系统数字化采购(程序代码部署程序包源码Java)
  • 实验3-传输层协议分析
  • [Java]PTA:jmu-Java-01入门-取数字浮点数