How to Git- Making Changes to Files

This tutorial is all about making changes to files in the repository and how to monitor the changes that you made. Let’s look those in details.

 

Changing text file content

Let’s add some text on “first.txt” file. Open up your “first.txt” from Git repository and add some text and save the file.

 

first.txt

Git Making Changes to Files

 

Check the working directory’s status using  git status.

The git status command shows the status of the working tree, which files have changed, which are staged and which are not part of the staging area.

 

Git status command
    $ git status
    On branch master
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)

             modified:   first.txt

       no changes added to commit (use "git add" and/or "git commit -a")

 

git knows “first.txt” file has been changed, but these changes are not yet committed to the repository. Git status log give you the instrection about what to do next. To add these changes to the repository, use git add. To undo the changes use git checkout.

git status shows which files have conflicts and gives an indication what the user can do with these changes.

Staging the changes (Adding)

Let’s add our modified text file and see the status message.

Git Add command
   git add first.txt
   git status

 

Git status command
    $ git add first.txt

    $ git status
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)

             modified:   first.txt


Now, the modified file is staged.  But it is not permanent in the repository. The commit will include the staged changes permanently to repository.

If you want to commit modifed file, use git commit -m

 

Git commit command
    $ git commit -m "First Change"
    [master d926afa] First Change
    1 file changed, 1 insertion(+)

 

 

Muhsin Yakkiparamban

Muhsin Yakkiparamban is the co-founder of Lauyou Learning. Muhsin holds Bachelor Degree in Civil Engineering from KMCT Calicut.

You may also like...