version rollback

Reprinted: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743858312764dca7ad6d0754f76aa562e3789478044000


We have successfully added and submitted a readme.txt file, now, it is time to continue working, so we continue to modify the readme.txt file to the following:

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

Now, run git statusthe command to see the result:

$ 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 statusThe command allows us to keep abreast of the current state of the warehouse. The above command tells us that readme.txt has been modified, but there are no modifications that are ready to be submitted.

Although Git tells us that readme.txt was modified, it would be nice to see what was modified. For example, you came back from abroad after a two-week vacation. When you went to work on the first day, you could not remember how to modify the readme.txt last time. Therefore, you need to use git diffthis command to see:

$ 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.

git diffAs the name implies, it is to view the difference, and the displayed format is the common diff format of Unix. As you can see from the above command output, we have added a word "distributed" to the first line.

After knowing what changes have been made to readme.txt, it is more assured to submit it to the warehouse. Submitting changes and submitting new files are the same two steps. The first step is git add:

$ git add readme.txt

Again there is no output. Before executing the second step git commit, let's run git statusto see the status of the current warehouse:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   readme.txt
#

git statusTell us that the changes to be submitted include readme.txt. Next, you can submit with confidence:

$ git commit -m "add distributed"
[master ea34578] add distributed
 1 file changed, 1 insertion(+), 1 deletion(-)

After submitting, we use git statusthe command to see the current state of the repository:

$ git status
# On branch master
nothing to commit (working directory clean)

Git tells us that there are currently no changes to commit, and that the working directory is clean.

summary

  • To keep track of the status of the workspace, use git statuscommands.

  • 如果git status告诉你有文件被修改过,用git diff可以查看修改内容。


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324699097&siteId=291194637