- `git rebase
- Used to move or rewrite commits from one branch onto another.
- Helps keep a cleaner commit history compared to
git merge. - Example:
sh git checkout feature-branch git rebase main - This applies all commits from
feature-branchon top ofmain, making it look like they were developed in sequence.
- git stash
- Temporarily saves your local changes without committing them.
- Useful when you need to switch branches but don’t want to commit unfinished work.
- Example:
sh git stash - This saves your changes and resets the working directory.
3. git stash pop
- Retrieves the last stashed changes and applies them back to your working directory.
- Example:
sh git stash pop - Unlike
git stash apply,popalso removes the stash after applying it.
Would you like an example scenario combining these? Or are you looking for a more video-style explanation? 🚀
If you’re asking about git log in the context of a vlog (or video demonstration), here’s how you can use it effectively:
git log - Viewing Commit History**git log` lets you see the history of commits in your repository. You can use different flags to customize the output:
Basic Usage:
git log- Shows a list of commits with details like commit hash, author, date, and message.
Enhanced Log Output (One-Line Format)**
git log --oneline- Displays commit history in a compact format:
e5d1a0b Fix login issue
a7f3c9d Add new feature
1c4e7b2 Initial commitGraph View (Great for Branch History)
git log --oneline --graph --all --decorate- Displays a graph of branches and commits, useful for visualization.
Filter Commits (By Author, Date, or Message)
- Show commits by a specific author:
git log --author="John Doe"- Show commits within a date range:
git log --since="2024-01-01" --until="2024-03-01"- Search commits by message:
git log --grep="fix"Using git log in a Vlog
If you’re making a video on git log, here are some ideas:
-
Show a messy commit history → then clean it up with
git rebase. -
Demonstrate branch merging → visualize it using
git log --graph. -
Use
git log --patch→ show code changes alongside commits.
Would you like help scripting a vlog/tutorial around this? 🚀
git commit - Saving Changes in Git
A git commit is how you save changes to your repository after staging them. It's like taking a "snapshot" of your code at a specific point.
Basic git commit Usage
- Stage changes (add files to be committed):
git add file.txt- Commit the staged changes:
git commit -m "Your commit message"- The
-mflag allows you to write a short message describing the changes.
More Advanced git commit Options
1. Commit All Changes (Without Staging)
git commit -am "Commit message"- The
-aflag commits all modified files (but not new files).
2. Edit the Last Commit Message
git commit --amend -m "Updated commit message"- Useful if you made a typo or need to tweak the last commit.
3. Create a Multi-Line Commit Message
git commit- This opens a text editor where you can write a detailed commit message.
4. Commit Without Opening an Editor
git commit --no-edit- Useful when amending a commit without changing its message.
Undoing Commits
1. Undo the Last Commit (Keep Changes)
git reset --soft HEAD~1- Moves the commit back to the staging area.
2. Undo the Last Commit (Discard Changes)
git reset --hard HEAD~1- Warning: This deletes the last commit and all changes!
**Using git commit
If you're making a video about git commit, here are some ideas:
- Show how commits track progress (before and after changes).
-
Demonstrate fixing a bad commit with
git commit --amend. - Explain commit best practices (clear messages, small commits).