管理修改 - morris131/morris-book GitHub Wiki

  1. 修改readme.txt

git is a version control system.

git is free software under the GPL.

git tracks changes.

  1. 添加到暂存区

$ git add readme.txt

$ git status

On branch master

Changes to be committed:

(use "git reset HEAD ..." to unstage)

    modified:   readme.txt
  1. 修改readme.txt

git is a version control system.

git is free software under the GPL.

git tracks changes of files.

  1. 提交至版本库

$ git commit -m "tracks change"

[master 1161148] tracks change

1 file changed, 2 insertions(+), 1 deletion(-)

  1. 查看状态

$ git status

On branch master

Changes not staged for commit:

(use "git add ..." to update what will be committed)

(use "git checkout -- ..." to discard changes in working directory)

    modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a") 发现第二次的修改并没有被提交, 操作过程: 第一次修改 -> git add -> 第二次修改 -> git commit

Git管理的是修改,用git add命令后,在工作区的第一次修改被放入暂存区,准备提交,但是,在工作区的第二次修改并没有放入暂存区,所以,git commit只负责把暂存区的修改提交了,也就是第一次的修改被提交了,第二次的修改不会被提交。/

  1. 查看工作区和版本库的区别

$ git diff HEAD -- readme.txt

diff --git a/readme.txt b/readme.txt

index 5cedd61..c05c601 100644

--- a/readme.txt

+++ b/readme.txt

@@ -1,3 +1,3 @@

git is a version control system.

git is free software under the GPL.

-git tracks changes.

\ No newline at end of file

+git tracks changes of files.

\ No newline at end of file

⚠️ **GitHub.com Fallback** ⚠️