今日已更新 358 条资讯 | 累计 30402 条内容
关于我们

Git Advanced: The Commands I Wish I Knew Earlier (2026)

Alex Chen 2026年06月02日 08:35 3 次阅读 来源:Dev.to

Git Advanced: The Commands I Wish I Knew Earlier (2026) Beyond add, commit, push. These are the Git commands that make you significantly more productive. Rewriting History (Use with Care!) # Modify your last commit (before pushing!) git commit --amend -m "Better message" # Add forgotten file to last commit: git add forgotten-file.js git commit --amend --no-edit # Keep same message, add the file # Interactive rebase — edit/squash/reorder past commits git rebase -i HEAD~5 # Edit last 5 commits # Opens editor with: # pick abc123 First commit # pick def456 Second commit # pick ghi789 Third commit # # Change 'pick' to: # reword = Edit commit message # squash = Merge into previous commit # fixup = Merge into previous (discard message) # edit = Pause for amending # drop = Remove commit entirely # Squash last 3 commits into one (non-interactive) git reset --soft HEAD~3 && git commit -m "Combined message" # Drop a specific commit from history git rebase -i <commit-before-target> # Then change 'pick' to 'drop' Stashing: Save Work Without Committing # Basic stash (saves all changes, including untracked if -u) git stash # Stash tracked changes git stash -u # Also stash untracked files git stash -p # Interactively choose what to stash # List and apply stashes git stash list # Shows all stashes # stash@{0}: WIP on feature-branch: abc1234 message # stash@{1}: WIP on main: def5678 other work git stash pop # Apply most recent + remove from list git stash apply # Apply but keep in list git stash apply stash@ { 1 } # Apply specific stash # Create named stash for easy reference git stash save "WIP: login feature" # Show what's in a stash before applying git stash show -p stash@ { 0 } # See the actual diff! # Drop/clear stashes git stash drop stash@ { 0 } # Remove one git stash clear # Remove all stashes # Practical workflow: # You're working on feature A → urgent bug report comes in git stash -u # Save all work git checkout -b hotfix/bug # Switch to fix branch # ... fix bug, commit, pu

本文内容来源于互联网,版权归原作者所有
查看原文