Git: 版本控制(3)

git diff 对比区别

  • 直接输入 git diff 后面不跟某个文件,即显示出所有文件的区别
  • git diff index.html 表示单独查看 index.html 文件的区别, - 表示上个版本的修改, + 表示当前修改后的
diff --git a/index.html b/index.html
index aa8038f..6acd0f2 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,5 @@
 
-
+
 
     
     
  • git add index.htmlindex.html 文件添加到暂存区
  • git status 显示当前要提交的修改
On branch master
Changes to be committed:
  (use "git reset HEAD ..." to unstage)

        modified:   index.html
  • git diff 查看区别,现在没有新的修改显示,因为我们把 index.html 文件添加到了暂存区,它会跟工作目录里的文件进行比较
  • 此时修改一下 index.html 保存
  • git status 查看修改后文件的状态
On branch master
Changes to be committed:
  (use "git reset HEAD ..." to unstage)

        modified:   index.html

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   index.html
  • git diff index.html 此时又会对比出上次修改的区别
diff --git a/index.html b/index.html
index 6acd0f2..239d8d4 100644
--- a/index.html
+++ b/index.html
@@ -4,7 +4,7 @@
     
     
     
-    Document
+    git diff
 
 
 
  • git commit -m '修改index.html的title' 提交当前修改,备注为 修改index.html的title

  • git push origin master 完成本次提交,并提交到主分支

你可能感兴趣的:(Git: 版本控制(3))