Tuesday, 16 July 2019

git: Tracked and untracked files


a. Tracked files
Files that are previous git snapshot are called tracked files. Tracked files can be in one of following states.

a.   Committed
b.   Modified
c.    Staging



Committed state
Data is successfully stored into local database

Modified state
File is changed, but the file data is not yet saved to local database.

Staging state
When you mark a file (or) files to go to your next commit state, those files are in staging state.

Untracked files
When a new file is added to the git repository it comes under untracked category. Whenever git sees a new file that is not in previous snapshot, then git treats this as untracked file.

Step 1: Cline the repository 'https://github.com/harikrishna553/gitHelloWorld.git' by executing below command.
git clone https://github.com/harikrishna553/gitHelloWorld.git.
$git clone https://github.com/harikrishna553/gitHelloWorld.git
Cloning into 'gitHelloWorld'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 9 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
$
$ls
gitHelloWorld


Step 2: Navigate to gitHelloWorld folder and create a new file called 'hobbies.txt'.
$cd gitHelloWorld/
$
$ls
README.md welcome.txt
$
$touch hobbies.txt
$
$ls
README.md hobbies.txt welcome.txt


Now execute the command 'git status'.
$git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

 hobbies.txt

nothing added to commit but untracked files present (use "git add" to track)

As you see the output, hobbies.txt file is untracked state.

You can add hobbies.txt tp staging area, by using add command.

git add hobbies.txt

$git add hobbies.txt 
$
$git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

 new file:   hobbies.txt


Once file is in staging area, you can commit the file to local git repository.

$git commit -m "Adding hobbies.txt file"
[master 3e9b168] Adding hobbies.txt file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 hobbies.txt
$
$git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean


Previous                                                    Next                                                    Home

No comments:

Post a Comment