Modify-stage-commit

Modifying existing file

Let us modify the contents of the first file and see how Git tracks the changes. Make some simple changes to the contents of the first file, save it and then run status command

git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   hello.txt

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

The file is modified but not yet staged for commit!

Staging the file(s)

We must not try to commit without staging the files, We use the same command to add the files to the staging area as before!

This commit will not be successful

git commit -m "hello modified"
On branch master
Changes not staged for commit:
        modified:   hello.txt

no changes added to commit

First add the modified files to the staging area and then commit

 git add .
git status

On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   hello.txt

This commit will be successful

git commit -m "hello modified"
[master 4d7bd7f] hello modified
 1 file changed, 1 insertion(+), 1 deletion(-)

Last updated