..." to">
当前位置:   article > 正文

Git操作_on branch master changes not staged for commit: (u

on branch master changes not staged for commit: (use "git add ..." to

1、git init 创建版本库

创建一个空目录

mkdir gitTest
$ cd gitTest
  • 1
  • 2

使用 git init命令,把这个目录变成Git可以管理的仓库

PS D:\gitTest> git init
Initialized empty Git repository in D:/gitTest/.git/
  • 1
  • 2

2、git add 新增文件,并提交

新增一个文件 readme.txt

Git is a version control system.
Git is free software.
  • 1
  • 2

使用 git add告诉Git,把文件添加到仓库

git add readme.txt
  • 1

用命令git commit告诉Git,把文件提交到仓库:-m后面输入的是本次提交的说明

git commit -m "wrote a readme file"
  • 1

3、git status 查看状态

修改readme.txt文件,改成如下内容:

Git is a distributed version control system.
Git is free software.
  • 1
  • 2

运行git status命令看看结果:

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

	modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4、git diff 查看不同

虽然Git告诉我们readme.txt被修改了,要用git diff这个命令看看修改了什么:

git diff readme.txt 
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.                   删除了
+Git is a distributed version control system.       新增的
 Git is free software.                              未修改
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

修改后,然后再提交 也是使用 git add ,之后看下状态

git add readme.txt
git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   readme.txt
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

告诉我们,将要被提交的修改包括readme.txt,下一步,就可以放心地提交了:

git commit -m "add distributed"
[master c2add21] add distributed
 1 file changed, 1 insertion(+), 1 deletion(-)
  • 1
  • 2
  • 3

提交后,再看下状态

git status
On branch master
nothing to commit, working tree clean
  • 1
  • 2
  • 3

5、git log 查看提交历史

再次修改文件为

Git is a distributed version control system.
Git is free software distributed under the GPL.
  • 1
  • 2

修改好了提交

git add readme.txt
git commit -m "append GPL"
[master 2bb4911]] append GPL
 1 file changed, 1 insertion(+), 1 deletion(-)
  • 1
  • 2
  • 3
  • 4

我们已经修改了三次,可以用 git log命令查询

git log
commit 2bb4911c23a25048f3c4c19d0b627ac4c06abb00 (HEAD -> master)
Author: tangcy <3247306211@qq.com>
Date:   Fri Apr 22 15:50:34 2022 +0800

    append GPL

commit c2add212bfe48e658f724521ba541b243b5ab0cc
Author: tangcy &l
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/264782
推荐阅读
相关标签
  

闽ICP备14008679号