The git rebase
command allows you to easily change a series of commits, modifying the history of your repository. You can reorder, edit, or squash commits together.
Typically, you would use git rebase
to:
Warning
Because changing your commit history can make things difficult for everyone else using the repository, it's considered bad practice to rebase commits when you've already pushed to a repository. To learn how to safely rebase, see About pull request merges.
Rebasing commits against a branchTo rebase all the commits between another branch and the current branch state, you can enter the following command in your shell (either the command prompt for Windows, or the terminal for Mac and Linux):
git rebase --interactive OTHER-BRANCH-NAME
Rebasing commits against a point in time
To rebase the last few commits in your current branch, you can enter the following command in your shell:
git rebase --interactive HEAD~7
Commands available while rebasing
There are six commands available while rebasing:
pick
pick
simply means that the commit is included. Rearranging the order of the pick
commands changes the order of the commits when the rebase is underway. If you choose not to include a commit, you should delete the entire line.
reword
reword
command is similar to pick
, but after you use it, the rebase process will pause and give you a chance to alter the commit message. Any changes made by the commit are not affected.
edit
edit
a commit, you'll be given the chance to amend the commit, meaning that you can add or change the commit entirely. You can also make more commits before you continue the rebase. This allows you to split a large commit into smaller ones, or, remove erroneous changes made in a commit.
squash
fixup
squash
, but the commit to be merged has its message discarded. The commit is simply merged into the commit above it, and the earlier commit's message is used to describe both changes.
exec
git rebase
No matter which command you use, Git will launch your default text editor and open a file that details the commits in the range you've chosen. That file looks something like this:
pick 1fc6c95 Patch A
pick 6b2481b Patch B
pick dd1475d something I want to split
pick c619268 A fix for Patch B
pick fa39187 something to add to patch A
pick 4ca2acc i cant' typ goods
pick 7b36971 something to move before patch B
# Rebase 41a72e6..7b36971 onto 41a72e6
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
Breaking this information, from top to bottom, we see that:
pick
), the commit SHA, and the commit message. The entire git rebase
procedure centers around your manipulation of these three columns. The changes you make are rebased onto your repository.41a72e6..7b36971
).RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4