Preview ng leksyon

Advanced Tools: Rebase, Stash, Cherry-pick and Tags

Moving on to the tools that distinguish a confident Git user from someone who only knows the basics. We'll explore rebase as an alternative to merge - showing when it makes history cleaner and when it turns it into a nightmare. We'll add stash for quickly 'shelving' unfinished work, cherry-pick for precisely transferring commits, and tags for marking releases.

git rebase git stash git cherry-pick
Ano ang matututunan mo sa leksyong ito
  • You'll be able to use git stash for context switching between tasks without losing changes.
  • You'll understand the difference between rebase and merge and will be able to make an informed choice between them depending on the context.
  • You'll learn to edit commit history using interactive rebase and mark release versions with tags.

Simula ng leksyon

The Problem: How to Shelve Unfinished Work

  • A sudden bugfix interrupts your work
  • You can't commit incomplete code
  • Git stash — temporary storage for changes
  • Tracks both staged and unstaged files
  • Returns the working directory to a clean state

Imagine: you're in the middle of working on a new feature when a critical bugfix comes in. You don't want to leave your work half-finished, but you can't commit incomplete code either. This is exactly what git stash is for — your digital temporary shelf. It's like pausing a game: your current progress is saved, and you can attend to other matters. When you return, everything will be exactly as you left it, including untracked files if you didn't forget the -u flag. This saves you from having to keep multiple tasks in mind at once.

Saving and Viewing Changes

  • git stash save — saves changes to the stash
  • git stash list — shows the list of saved changes
  • Each stash is assigned a unique ID
  • stash@{0} — most recently saved change
  • The stash preserves the working directory state

Let's explore how to work with git stash in practice. The command git stash save will save all changes in the working directory and staged files, returning you to a clean state. Your work won't be lost — it will go into a special storage area. To verify that your changes have been saved, run git stash list. You'll see a list of all stashed tasks with unique identifiers like stash at zero. This is particularly useful when you need to quickly switch between tasks without losing progress.

# Save current changes
git stash save "WIP: New feature login form"

# Check the list of saved changes
git stash list

# View the contents of the latest stash
git stash show -p

Recovering Stashed Changes

  • git stash pop — applies and removes the most recent stash
  • git stash apply — applies without removing
  • Code conflicts may occur
  • Conflicts must be resolved manually
  • stash@{n} — refers to a specific stash

When you're ready to return to your stashed work, you have two options. The git stash pop command will apply the most recent stashed changes and remove them from the stash list. If you want to review the changes or apply them multiple times, use git stash apply — the changes will remain in the stash. Important: if the code has changed since you created the stash, conflicts may occur. In this case, Git will alert you to the problem, and you'll need to resolve the conflicts manually.

# Restore the most recent stashed changes
git stash pop

# OR apply without removing
git stash apply

# Apply a specific stash by index
git stash apply stash@{1}

Buong leksyon ay para sa subscription

25 pang slide sa buong bersyon.

Mabubuksan ang video, lahat ng slide, tala, pagsusulit, AI tutor, at interview pagkatapos mag-sign in at mag-subscribe.

Mag-sign in o magparehistro Mag-subscribe

Nilalaman ng leksyon

  1. The Problem: How to Shelve Unfinished Work
  2. Saving and Viewing Changes
  3. Recovering Stashed Changes
  4. When Stash Can Be Harmful
  5. How Branch Merging Works
  6. Rebase: Rewriting Commit History
  7. When to Use What: Practical Scenarios
  8. The Dangers of Rebase: What Could Go Wrong
  9. What is Rebase and Why Do We Need It
  10. Performing Rebase: Step-by-Step Guide
  11. Resolving Rebase Conflicts
  12. Interactive Rebase: Your Commit History Editor
  13. Key Commands in Interactive Rebase
  14. Practice: Creating the Perfect History
  15. Warning: Changing Published History
  16. Why You Shouldn't Rebase Shared Branches
  17. Recovering from a Failed Rebase
  18. Safe History Modification
  19. Why Use Cherry-Pick in Git
  20. How to Use git cherry-pick
  21. When to Choose: cherry-pick vs merge vs rebase
  22. Git Tags: Bookmarks for Important Commits
  23. Creating Annotated and Lightweight Tags
  24. Publishing Tags to a Remote Repository
  25. Scenario: Hotfix in the Middle of Development
  26. Integrating Changes Using Rebase and Cherry-Pick
  27. Common Pitfalls and How to Avoid Them
  28. Summary: Your New Git Mastery Toolkit

Mga artikulo tungkol sa araling ito

Lahat ng leksyon ng kurso

  1. Introduction: Git from Scratch to Confident Developer
  2. Why Git is Essential - And Why It's a Job Requirement
  3. Installation and Setup: Getting Git Ready for First Use
  4. First Repository: init, add, commit, and the Magic of the Index
  5. Reading History: log, diff, show and Navigating the Past
  6. Branches: The Parallel Reality of Your Code
  7. Undoing Mistakes: restore, reset, revert — Doing It Right and the Dangers
  8. GitHub and Remote Repositories: Your Code in the Cloud
  9. Team Collaboration: Forks, Feature Branches, and Pull Requests
  10. Merge Conflicts: Don't Panic - Understanding and Resolving Them
  11. Git Workflows in Real Teams: Choosing the Right Approach
  12. Advanced Tools: Rebase, Stash, Cherry-pick and Tags
  13. Final Project: Simulating Real Team Development