Resolve a commit conflict
Continuing a rebase in Git allows you to advance the process of managing and refining your commit history after resolving conflicts or making changes during an ongoing rebase operation.
In this part of our tutorial, we will explore the process of resolving a conflict in order to continue a rebase in Git.
Go to the git-tutorial/tutorial6
directory you previously downloaded.
When you examine the history of this repository, it will look like the following:
We are going to modify the commit with the message “append description of the commit command.”
To do that, we will use the git rebase -i command.
$ git rebase -i HEAD~~
Your default text editor will open listing commits from HEAD
down to HEAD~~
, as shown below.
pick 9a54fd4 append description of the commit command
pick 0d4a808 append description of the pull command
# Rebase 326fc9f..0d4a808 onto d286baa
#
# 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 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.
#
On the first line, change the word pick
to edit
, then save and quit.
You will see the following output and be checked out of that commit.
Stopped at d286baa... append description of the commit command
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
Open the sample.txt
file and make the change as shown below.
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
commit: Record index state.
pull: Obtain the content of the remote repository
Use git commit --amend
to commit the change.
$ git add sample.txt
$ git commit --amend
Then execute git rebase --continue
to complete the rebase process.
$ git rebase --continue
While running a rebase on your current branch, you may run into conflicts in your changes. To proceed, you must manually resolve those conflicts, then run git add
and git rebase --continue
. There is no need to issue new commits to resolve the conflicts.
However, if you want to stop rebasing, you can call git rebase --abort
, which will revert and exit the entire process and successfully modify the commit.
In cases where you specify edit
on more than a single line when calling git rebase -i
, you will be prompted to modify each of the commits one at a time.