• Git 提交修改内容和查看被修改的内容


    我们将仓库里的readme.txt文件修改一下,改成如下内容:

    Git is a distributed version control system
    Git is free software.

    运行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")

    git status命令可以让我们时刻的掌握仓库的当前状态,上面的信息告诉我们,readme.txt被修改过了,但是还没有准备提交修改

    Git虽然告诉我们readme.txt被修改了,但是如果能看到修改了什么内容就是最好的了,好比你忘记了上次怎么修改的readme.txt,

    这时候你就要用 git diff这个命令看看:

    $ git diff readme.txt
    diff --git a/readme.txt b/readme.txt
    index 58998b5..9c3f69a 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.
    No newline at end of file

    git diff 顾名思义就是查看difference,显示格式正是Unix通用的diff格式,可以从上面的输出信息看出,第一行添加了一个"distributed"单词。

    知道了对readme.txt作了什么修改后,再把它提交到仓库就放心多了,提交修改和提交新文件是一样的,分add和commit两步:

    LV@LV-PC MINGW32 /c/gitRespository (master)
    $ git add readme.txt            //添加修改的文件

    LV@LV-PC MINGW32 /c/gitRespository (master)
    $ git status                 //当前仓库的状态:将要被提交的修改包括readme.txt
    On branch master
    Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)

    modified: readme.txt


    LV@LV-PC MINGW32 /c/gitRespository (master)
    $ git commit -m "modify the readme.txt commit"  //提交
    [master 4b1d71b] modify the readme.txt commit
    1 file changed, 1 insertion(+), 1 deletion(-)

    LV@LV-PC MINGW32 /c/gitRespository (master)
    $ git status              //当前仓库状态:没有需要提交的修改,工作目录是干净的
    On branch master
    nothing to commit, working directory clean

  • 相关阅读:
    显示图案
    圆的面积和周长
    Python基础--list列表删除元素
    Python基础--列表添加元素
    Python基础--列表创建访问删除
    Python基础--序列简介
    一个网页通用的测试用例(转载)
    测试计划与测试方案的区别
    判断一棵树是否是二叉平衡树
    判断丑数与寻找丑数
  • 原文地址:https://www.cnblogs.com/LvLoveYuForever/p/5492449.html
Copyright © 2020-2023  润新知