edit drop
- Git course
- Advanced
- Lesson 3/56
- 4 min
Learn the edit and drop commands.
edit and drop
During an interactive rebase, edit pauses the operation after replaying a commit. This allows you to modify files or amend the commit. drop removes the selected commit from the rewritten history.
pick a12bc34 Add reports page
edit b23cd45 Add report filters
drop c34de56 Add temporary debug outputThese operations rewrite history, so they should be used carefully, especially on shared branches.
Splitting a commit
If a commit contains multiple independent changes, you can pause with edit and split it into smaller commits. When rebase pauses, git reset HEAD^ removes the last commit while leaving its changes in the working area. You can then stage files separately, create new commits, and continue with git rebase --continue.
git reset HEAD^
git add page.html
git commit -m "Add page markup"
git add page.css
git commit -m "Add page styles"
git rebase --continuePractice Split a commit into two parts
Assume the rebase has paused because of edit. Undo the last commit, save report.html as a separate commit, then save report.css as a second commit. Finally, continue the rebase.
Starter code
# Son commit'i geri al
# HTML dosyasını ayrı kaydet
# CSS dosyasını ayrı kaydet
# Rebase işlemine devam etSample solution
git reset HEAD^
git add report.html
git commit -m "Add report markup"
git add report.css
git commit -m "Add report styles"
git rebase --continueExpected output
Last commit reset; changes kept. HTML changes committed. CSS changes committed. Rebase continued.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 You want to pause after replaying a commit so you can modify its files or amend it. Which todo command is appropriate?
- squash
- edit Correct answer
- pick
- drop
Explanation: edit pauses the rebase after replaying the commit and allows you to make changes.
2 Continue the rebase
git rebase ____
git rebase --continue
Explanation: After editing is complete, use the --continue option to resume the ongoing rebase.
3 Commit editing options
| Term | Meaning |
|---|---|
edit |
Modify a commit |
drop |
Remove a commit from history |
git reset HEAD^ |
Undo last commit but keep changes |
git rebase --continue |
Continue the rebase operation |