Git state about files

First, the readme

  In a rough finish learning Git tutorial, especially for the management of this branch of learning section, a bit powerless, learn the advantages of mixed feeling, all specially in writing this article, find out knowledge of which involved.

Two, git status of use

1, the learngit folder into a warehouse after the first use of git status to view the status of the warehouse

1  $ git Status
 2  the On Branch Master a main branch of Master
 3  
4  No commits yet has not submitted
 5  
6 Nothing to the commit (the Create / Copy Files and use " git the Add " content to track) is not submitted (create / copy files and use "git add" to track)

2, create a file readme.txt, write to Hello world !, the second use git status to view the status of the warehouse

1  $ git Status
 2  the On Branch Master
 3  
4  No commits yet
 5  
6  untracked Files: no trace file
 7    (use " git add <file> ... " to the include in the What committed by Will BE) using git add <file> go add it and submit
 8  
9          the Readme.txt file name
 10  
11 Nothing But added to the commit untracked files Present (use " git the Add " to Track)  
No added content for submission, but there is no file can be added using git add to track

 At this moment, Git no right to manage the readme.txt file (no add, that is, track, record to the staging area)

3, add files to the staging area, the third use git status to view the status of the warehouse

1  $ git Status
 2  the On Branch Master
 3  
4  No commits yet
 5  
6  Changes to BE committed: the staging has been submitted (staging area)
 7    (use " git RM --cached <File> ... " to unstage) use "git rm - cached <file> ..." to cancel storing
 8  
9          new new File: the Readme.txt

4, modify readme.txt, add a line Hello Git !, fourth use git status to view the status of the warehouse

 1 $ git status
 2 On branch master
 3 
 4 No commits yet
 5 
 6 Changes to be committed:     保存的内容为Hello world!
 7   (use "git rm --cached <file>..." to unstage)
 8 
 9         new file:   readme.txt
10 
11 Changes not staged for commit:
12   (use "git add <file>..." to update what will be committed)    更新提交
13   (use "git checkout -- <file>..." to discard changes inworking directory) may be discarded modified workspace
 14  
15          Modified: the Readme.txt modified file.

5, add files to the staging area, the fifth use git status to view the status of the warehouse

1 $ git status
2 On branch master
3 
4 No commits yet
5 
6 Changes to be committed:
7   (use "git rm --cached <file>..." to unstage)
8 
9         new file:   readme.txt

6, submission of documents to the local library, the sixth-use git status to view the status of the warehouse

1  $ git Status
 2  the On Branch Master
 3 Nothing to the commit, Working Tree Clean empty workspace (workspace files consistent with the content library version)

Third, undo changes

In order to facilitate learning, reconfigure the warehouse, the warehouse is initialized (readme.txt file content only one sentence, Hello world !, not add, nor commit)

1, the file add, and then add content Hello Git! Check the status of

 1 $ git status
 2 On branch master
 3 
 4 No commits yet
 5 
 6 Changes to be committed:
 7   (use "git rm --cached <file>..." to unstage)
 8 
 9         new file:   readme.txt
10 
11 Changes not staged for commit:
12   (use "git add <file>..." to update what will be committed)
13   (use "git checkout -- <file>..." to discard changes in working directory)  可以看见这句话

使用命令git checkout -- <file>退回到暂存区的状态

 

1 $ git checkout -- readme.txt
2 $ cat readme.txt
3 Hello world!

 

2、对文件进行add,查看状态

1 $ git status
2 On branch master
3 
4 No commits yet
5 
6 Changes to be committed:
7   (use "git rm --cached <file>..." to unstage)
8 
9         new file:   readme.txt

要想撤销暂存区的内容使用以下命令:

1 $ git reset HEAD readme.txt
2 fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
3 Use '--' to separate paths from revisions, like this:
4 'git <command> [<revision>...] -- [<file>...]'

竟然会出错,不科学啊!原来是这个文件没有提交过,也就是没有进行commit,再次尝试。

先将有Hello world!文件进行提价,再次进行操作。

1 $ git reset HEAD readme.txt
2 Unstaged changes after reset:
3 M       readme.txt
4 
5 $ git checkout -- readme.txt  这一步必须要有
6 
7 $ cat readme.txt
8 Hello world!

四、删除文件

1、手动删除了readme.txt文件,可以恢复

$ rm readme.txt

$ ll
total 0


$ git checkout -- readme.txt  将暂存区的文件恢复到工作区

$ ll
total 1
-rw-r--r-- 1 86173 197609 13 8月   7 12:00 readme.txt

2、手动删除了readme.txt文件,并且删除了暂存区的文件

 1 $ rm readme.txt
 2 
 3 $ ll
 4 total 0
 5 
 6 $ git rm readme.txt
 7 rm 'readme.txt'
 8 
 9 
10 $ git reset HEAD readme.txt    将版本库里的文件恢复到暂存区
11 Unstaged changes after reset:
12 D       readme.txt
13 
14 $ ll
15 total 0
16 
17 $ git checkout -- readme.txt  将暂存区的文件恢复到工作区
18 
19 $ ll
20 total 1
21 -rw-r--r-- 1 86173 197609 13 8月   7 12:06 readme.txt

 

Guess you like

Origin www.cnblogs.com/lilong74/p/11313394.html