1. Check the git repository file change status
There are changes in the Git repository file four states, in addition to file Unmodified state because the state did not do than change the default display, other states are changes to the file can be viewed by git status
View Git status of the record commonly used commands,
View git repository status
git status
Get a git repository, enter the warehouse, first execute this command to view
[CI-node1 the root @ ~] # CD / Data / git_test / [the root CI @ - node1 git_test] # [the root CI @ - node1 git_test] Status # Git the On Branch master // the default master branch on the master branch Initial the commit // initialize the commit Nothing to the commit (the create / copy files and use " git add " to Track) // now empty warehouse you can create, copy files can then use git add command
Create a, b, c three files in the workspace.
[root@ci-node1 git_test]# touch a b c [root@ci-node1 git_test]# ll total 0 -rw-r--r-- 1 root root 0 Aug 24 22:36 a -rw-r--r-- 1 root root 0 Aug 24 22:36 b -rw-r--r-- 1 root root 0 Aug 24 22:36 c
Look Git records state, we can see from the results below, the new three files in the Git space belong Untracked files, stored in the work area
[root@ci-node1 git_test]# git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) a b c nothing added to commit but untracked files present (use "git add" to track)
File in the Git repository directory changes have occurred in the operation of the default workspace Git, Git does not actively managed. If you want Git to manage these changes, you need to take the initiative to inform Git. There are three kinds of commands to tell Git (git add / rm / mv)
2. workspace file changes added to the staging area git add
git add is the first to tell Git command, which tells Git we have added file changes, are operated git add command files (changes) will be in Git staging area
[root @ CI-node1 git_test] # git the Add A // add a single file changes to the staging area [root @ CI-node1 git_test] # git Status // Check that the file status, a file already in the temporary area of the On Branch Master Initial the commit Changes committed to BE: (use " git RM --cached <File> ... " to unstage) new new File : a untracked Files: (use " git the Add <File> ... " to the include in the What committed by Will BE) b c
git add to a file from the working directory to the staging area, Untracked from state to state Staged
Staging areas are index files, initialize the warehouse when the index file does not exist in the .git directory, when using git add files to the staging area to move the index file is generated
[root@ci-node1 git_test]# cd .git/ [root@ci-node1 .git]# ll total 16 drwxr-xr-x 2 root root 6 Aug 24 00:17 branches -rw-r--r-- 1 root root 92 Aug 24 00:17 config -rw-r--r-- 1 root root 73 Aug 24 00:17 description -rw-r--r-- 1 root root 23 Aug 24 00:17 HEAD drwxr-xr-x 2 root root 242 Aug 24 00:17 hooks -rw-r--r-- 1 root root 96 Aug 24 22:49 index // index文件生成 drwxr-xr-x 2 root root 21 Aug 24 00:17 info drwxr-xr-x 5 root root 40 Aug 24 22:49 objects drwxr-xr-x 4 root root 31 Aug 24 00:17 refs
We can use git add. Git add * multiple files at once changes added to the staging area
The working directory all files submitted to the staging area
[root@ci-node1 git_test]# git add .
Output
// Check that the file status, three files are in the staging area in the [root @ CI - node1 git_test] # git Status the On Branch Master Initial the commit Changes committed to BE: (use " git RM --cached < File> ... " to unstage) new new File : A new new File : b new new File : c
3. the staging area file changes rollback git rm
Git Git rm command is used to tell before we want to use git add file to add the changes to come, no records from the Git Git staging area inside. There are two methods to get out, one is returned from the staging area to the work area, the other is directly discarded file changes. Let us try to return to the work area c, b discarded.
git rm move a file from scratch back to the working directory, the state Staged become unstaged
git rm --cached
git rm -f
git rm --cached
// c changes the workspace from scratch
// The c changes from scratch workspace [the root @ CI-node1 git_test] # Git RM - cached c RM ' c '
//查看 c 是否已经移回工作区 [root@ci-node1 git_test]# git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: a new file: b Untracked files: (use "git add <file>..." to include in what will be committed) c
git rm -f
// b will delete files directly from the git space, it is also deleted from the staging area and a work area.
// will b deleted files directly from the git space, it is also deleted from the staging area and a work area. [root @ CI-node1 git_test] # git RM - fb RM ' b ' // check the status of [root @ CI- node1 git_test] # git Status the On Branch Master Initial the commit Changes committed to BE: (use " git RM --cached <file> ... " to unstage) new new file : A untracked files: (use " git the Add <file> ... " to the include in the What committed by Will BE) c // current directory has no files b [root @ ci-node1 git_test]# ll total 0 -rw-r--r-- 1 root root 0 Aug 24 22:36 a -rw-r--r-- 1 root root 0 Aug 24 22:36 c
4. Submit git commit
The documents submitted to the local warehouse from scratch
When we finished after the file additions and deletions to operate in the warehouse district, and use git add the file changes recorded after the staging area, you can begin to submit it to the local Git repository.
The staging area Submit git commit -m ""
Back "," to describe what is described in this submission
[root@ci-node1 git_test]# git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: a
// The temporary area of the file submitted to the local repository a.txt
// The document submitted to the staging area a.txt local repository root @ CI-node1 git_test] # git the commit -m " the commit A " [Master (root - the commit) 73d7230] the commit A 1 File changed, 0 insertions ( +), 0 deletions (- ) the Create the MODE 100644 a // view the status of the work area, the work area is now clean work area, can be understood as the working directory, // cache, local memory storage warehouse three areas are the same , git three buffer area, working directory, local warehouses holds a file, a file in the three regions is consistent with [root @ CI- node1 git_test] # git Status the on Branch Master Nothing to the commit, working Tree Clean / / a file was submitted to the local repository, a document management really is git
Documents submitted to local warehouses in three regions working directory, staging area, a local warehouse store, copy
The location of the staging area file is moved / renamed git mv
Git mv 命令用于告诉 Git 我们想把之前用 git add 添加的文件直接在暂存区里重新命名或移动到新位置。
git mv 对缓存区和工作目录的文件命名和移动到新位置
//将 a 文件改名为 a.txt
//将 a 文件改名为 a.txt [root@ci-node1 git_test]# git mv a a.txt [root@ci-node1 git_test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: a -> a.txt // 直接告诉状态renamed [root@ci-node1 git_test]# ll total 0 -rw-r--r-- 1 root root 0 Aug 24 22:36 a.txt
再提交
[root@ci-node1 git_test]# git commit -m "rename a to a.txt" [master cc8bd80] rename a to a.txt 1 file changed, 0 insertions(+), 0 deletions(-) rename a => a.txt (100%) [root@ci-node1 git_test]# git status On branch master nothing to commit, working tree clean