Version Control
Git: Getting started
Git: Getting started
  • Introduction
    • What is version control
      • Distributed VCS
      • Summary
    • What is Git?
      • A Short History of Git
      • Under the hood
      • The Three States
    • What is GitHub?
  • Setting up Git
    • Installation
    • First time setup
    • Creating a repo
  • Basic operations
    • Recording Changes
      • Add another file
      • Modify-stage-commit
      • Modify-direct commit
      • View log
    • Undo changes
      • Restore (modified)
      • Restore (staged)
      • Amend (rare)
    • Clone repos
  • Remote Repos
    • Configure remote
    • Push to remote
      • Push branches
  • Reference
    • My Git Tutorials
    • Git Official
    • Others
Powered by GitBook
On this page
  • Modifying existing file
  • Staging the file(s)
  1. Basic operations
  2. Recording Changes

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(-)

PreviousAdd another fileNextModify-direct commit

Last updated 2 years ago