git添加文件和查看版本异同

git添加文件

添加文件到Git仓库,分3步:

  1. 找到所在文件夹右键鼠标打开git bash;找到所需要进行传送的文件(个人编辑了一个test.md格式文件)
  2. 下面3-4的指令都在git bash里操作
  3. 使用命令$ git init把文件夹初始化。(在文件夹内部会生成.git文件夹,如果没有看到.git文件,就在git bash里输入ls -ah)
  4. 使用命令git add ,注意,可反复多次使用,添加多个文件;使用命令git commit -m ,完成。(注意在add文件的时候要用文件名+文件格式
$ git add test.md 
$ git commit -m "my first try" 

git查看版本异同

对于同一个文件,在文件被修改可以在git bash里查看其状态。输入git status

$ git status

得到结果

On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.md

no changes added to commit (use "git add" and/or "git commit -a")

查看修改的文件和原文件异同
输入命令git diff + 被查文件

$ git diff test.md

得到结果

diff --git a/test.md b/test.md
index 9962158..89c6851 100644
--- a/test.md
+++ b/test.md
@@ -1,4 +1,10 @@
 Git is a version control system.
 Git is free software.
+
+```
+
+```
+Git is a distributed version control system.
+Git is free software.
\ No newline at end of file

猜你喜欢

转载自blog.csdn.net/matthewchen123/article/details/113092326
今日推荐