Summary: This text explains key Git commands and workflows for version control in collaborative development. It highlights the differences between merging and rebasing, and the importance of using git revert instead of git reset --hard for shared repositories. Understanding these concepts helps maintain a clean commit history and effective team collaboration.
Merge vs. Rebase: Both integrate changes, but merge preserves history with merge commits, while rebase creates a linear history by reapplying commits. Use merge for shared branches and preserving history; use rebase (cautiously) for cleaning up local feature branches before merging. (View Highlight)
Note: Merge creates new commit with 2 parents, combining the branches. Rebase cuts/pastes the commits to the target branch, cleaner history, but more dangerous.
Pull vs. Fetch:fetch downloads remote changes without integrating them; pull downloads and immediately merges them. Use fetch to inspect changes before integrating; use pull for a quick update when you expect no conflicts. (View Highlight)
Note: Fetch updates your remote tracking repo with recent changes, pull does that AND applies the changes to your local branch
Reset --hard vs. Revert:reset --hard discards changes and rewrites history (dangerous for shared branches); revert creates a new commit to undo changes (safe for shared branches). Use reset --hard only for local, unpushed mistakes; use revert for undoing changes on shared branches. (View Highlight)
Note: git reset erases history, git revert creates a new commit that undoes the changes.