CHAPTER 7: Committing, Skipping Staging, Removing & Moving Files
Commit the Changes We've Made
First, we stage changes using:
git add <filename> or
git add .(for all changes).
Then we commit them with:
git commit -m "your commit message"
Commits:
What If I Skip Staging? π€¨
You can use git commit -am "message" to skip staging.
- β Works for modified files already tracked.
- β New (untracked) files are ignored unless explicitly added.
ποΈ Removing Files in Git
Sometimes, you need to remove files from both:
- ποΈ Working Directory (your project folder)
- π¦ Staging Area (what's going into your next commit)
Use this command:
π― Example:
This command:
- β Deletes
old_data.csvfrom your folder - π Stages its removal so the deletion is included in your next commit
π€ What if I delete the file manually (outside Git)?
Git will notice itβs missing and show this in git status:
But it wonβt be staged until you run:
π« Want to keep the file but stop tracking it?
Use this command to untrack the file without deleting it from disk:
This is super useful for removing sensitive or unnecessary files like logs, build folders, or API keys.
π‘ Tip:
Once removed, add that file to .gitignore to prevent future accidental tracking.
π Moving or Renaming Files in Git
Renaming or moving a file? Git has a special command:
π¦ Example:
This command:
- π Renames or moves the file in your folder
- π Automatically stages the change for the next commit
π§ Why use git mv instead of renaming manually?
If you rename manually (via File Explorer or command line), Git treats it like:
- β One file deleted
- β One new file added
This can clutter your history with unnecessary deletions and additions.
π΅οΈββοΈ Fun Fact:
Git uses smart algorithms to detect renamesβeven if you move manually! If content remains mostly the
same, Git will show it as a rename in git diff or git status.
But using git mv makes your intent clear and keeps your commits cleaner.
π§ Quick Quiz: Test Your Understanding!
What command will commit only modified (already tracked) files without staging first?