Git Tutorial 7-file states

Source: Internet
Author: User
Tags one more line

File States overview

Every file in your working directory are mainly in one of 2 states:

1. tracked:all files that were committed to the last snapshot in Git repository is in state tracked. They can be one of the following states:

1.1 Unmodified:files you checkout from repository and Haven ' t edited anything yet.

1.2 Modified: Files Checkout from repository and has ever edited something since your last commit.

1.3 Staged:files you ' ve modified and added to staging area.

2. untracked:all files that were not in the last snapshot and is not in the staging area.

States diagram Below

Figure 7.1

There is couples of transfer operations that make files from one state to another. Today we ' re going to explain what's mean to each of the them and how to does to make that happen.

Suppose this was my working directory as below screen shown. I have 3 files which is all on my last snapshot.

Figure 7.2

untracked

First of all, let me create a new file in my working directory:

Echo ' This is a HTML project ' > readmegit status

Let's take the file README as an example. The output is displayed as below

Figure 7.3

File README is now in the state untracked. See it is understand the list of ' untracked files: '.

Untracked-Staged

See the figure 7.1, as the IT says we add the file README to staging area.

git add README
git status

That time after running the commands above, you can see the file README now are on staging area waiting for commit.

Figure 7.4

Staged-unmodified

Obviously it is time to commit the file changes on stage

Git commit-m "Add File README"

The state of the file README are changed from staged to unmodified.

Figure 7.5

Unmodified-untracked

As the figure 7.1 tells us, the change happens by ' Remove the file '. If the file is removed, was gone, I think it doesn ' t make any sense. No file no state, what does mean to untracked? So one hand we must remove the file from the last snapshot, which has Git no track for it. On the other hand we want to keep this file on your working directory in your hard drive.

That's the reason why the option--cached is used.

git rm--cached README

Figure 7.6

You can see the file README are still in working directory (command LS displays this) and to be under the list of untracked Files.

Unmodified-Modified

The common thing between these 2 states is the, files were in your last snapshot. The different thing between them is, if you edit files since your last commit Git sees them as modified, otherwise as Unmodified. The transfer from unmodified to modified are to change your files.

Let's suppose that file README are committed to my local repo and now I ' m adding one more line text appending to it.

git ls-filesecho ' Hello world\r\n ' >> readmegit status

Look at the output

Figure 7.7

Modified-Staged

That's similar to the state change "untracked-staged".

git add README

The output also look for the same as Figure 7.4

Conclusion

untracked-Staged:git Add <file>

Staged-Unmodified:git Commit

Unmodified-Untracked:git RM--cached

Unmodified-Modified: (You can do any change to files which Git is tracking.)

Modified-Staged:git Add <file>

Git Tutorial 7-file states

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.