DEV Community

Sudhakar V
Sudhakar V

Posted on

GIT DAY 4

  1. `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-branch on top of main, making it look like they were developed in sequence.
  1. 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, pop also 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
Enter fullscreen mode Exit fullscreen mode
  • Shows a list of commits with details like commit hash, author, date, and message.

Enhanced Log Output (One-Line Format)**

git log --oneline
Enter fullscreen mode Exit fullscreen mode
  • Displays commit history in a compact format:
  e5d1a0b Fix login issue
  a7f3c9d Add new feature
  1c4e7b2 Initial commit
Enter fullscreen mode Exit fullscreen mode

Graph View (Great for Branch History)

git log --oneline --graph --all --decorate
Enter fullscreen mode Exit fullscreen mode
  • 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"
Enter fullscreen mode Exit fullscreen mode
  • Show commits within a date range:
  git log --since="2024-01-01" --until="2024-03-01"
Enter fullscreen mode Exit fullscreen mode
  • Search commits by message:
  git log --grep="fix"
Enter fullscreen mode Exit fullscreen mode

Using git log in a Vlog
If you’re making a video on git log, here are some ideas:

  1. Show a messy commit history → then clean it up with git rebase.
  2. Demonstrate branch merging → visualize it using git log --graph.
  3. 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

  1. Stage changes (add files to be committed):
   git add file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Commit the staged changes:
   git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode
  • The -m flag 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"
Enter fullscreen mode Exit fullscreen mode
  • The -a flag commits all modified files (but not new files).

2. Edit the Last Commit Message

git commit --amend -m "Updated commit message"
Enter fullscreen mode Exit fullscreen mode
  • Useful if you made a typo or need to tweak the last commit.

3. Create a Multi-Line Commit Message

git commit
Enter fullscreen mode Exit fullscreen mode
  • This opens a text editor where you can write a detailed commit message.

4. Commit Without Opening an Editor

git commit --no-edit
Enter fullscreen mode Exit fullscreen mode
  • Useful when amending a commit without changing its message.

Undoing Commits

1. Undo the Last Commit (Keep Changes)

git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode
  • Moves the commit back to the staging area.

2. Undo the Last Commit (Discard Changes)

git reset --hard HEAD~1
Enter fullscreen mode Exit fullscreen mode
  • 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:

  1. Show how commits track progress (before and after changes).
  2. Demonstrate fixing a bad commit with git commit --amend.
  3. Explain commit best practices (clear messages, small commits).

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay