Wednesday, May 12, 2021

Git Basics - 2

Git -a and Edit files

git commit -am "Adding more content"

-a = add staging and directly commit

this is tracked by git

to get the tracked files from git


git ls-files

this will output all the files tracked by the current repository

to explain more

let's add a new file to "newfile.txt" to working directory


git status - will output untracked file of "newfile.txt"

git ls-files - will not have the "newfile.txt"

add the file and see

git add newfile.txt


git status  - nothing to show

git ls-files - will show your "newfile.txt" in the bottom of the list. it's a tracked file from git now.


Editing Files

git status

output

Changes to be committed:

new file: newfile.txt


Changes not staged for commit:

modified: hip.txt


Here newfile.txt is staged. So it is ready to committed.

Other is still in working directory. Not yet staged.

Note: you have to stage before commit


git commit -m "Adding new file"

This will commit file only from staging area."newfile.txt"


Now run git status

you will  still  have modified: hip.txt  Not been commit yet.

we need to add that file to staging area. we do in longer way

git add hip.txt

git status

change has been moved to staging area

Changes to be committed:

modified: hip.txt

Now modified the file one more time.


git status

Changes to be committed:

modified: hip.txt

Changes not staged for commit:

modified: hip.txt

So even in the same file git can track changes are to committed(staged) and changes are yet to be staged(working directory)

Now we need to add this modification

git add hip.txt

So here why we are using "add" to modified file.

add index the modified content

git status

now both changes are in staging area

git commit -m "more changes are added"

git status

nothing  to commit, working directory clean

No comments:

Post a Comment