krishna kurtakoti
krishna kurtakoti

Reputation: 128

git rebase the feature branch into the master branch

I am trying to do the rebasing of a feature branch into the master branch. I am facing the problem in the step 7 and onwards. Can you help in identifying the issue with the git rebase. I am facing the problem even after resolving the merge conflicts in the step 7.

Reference: 1. https://dev.to/joemsak/git-rebase-explained-and-eventually-illustrated-5hlb

  1. Create new branch: new-branch-one
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git checkout -b new-branch-one
Switched to a new branch 'new-branch-one'
  1. Modify a file. Add a new commit in the new branch
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git commit -m 'commit D'
[new-branch-one 487ec55] commit D

Modify a file. Other commit in the new branch

krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git commit -m 'commit E'
[new-branch-one 78b0680] commit E
 1 file changed, 2 insertions(+)
  1. Checkout the master branch
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

Take a pull from remote master being on the local master branch

krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git pull origin master
Username for 'https://gitlab.com': krishnagk
Password for 'https://[email protected]': 
From https://gitlab.com/krishnagk/testrebaseone
 * branch            master     -> FETCH_HEAD
Already up to date.
  1. Create new branch: f-two
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git checkout -b f-two
Switched to a new branch 'f-two'

Modify a file. Add a new commit in the new branch

krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git commit -m 'commit f'
[f-two 99210bc] commit f
 1 file changed, 2 insertions(+)

Modify a file. Other commit in the new branch

krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git commit -m 'commit g'
[f-two 6ed028f] commit g
 1 file changed, 2 insertions(+)

Push the new branch to remote repository.

krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git push origin f-two
Username for 'https://gitlab.com': krishnagk
Password for 'https://[email protected]': 
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 505 bytes | 505.00 KiB/s, done.
Total 6 (delta 1), reused 0 (delta 0)
remote: 
remote: To create a merge request for f-two, visit:
remote:   https://gitlab.com/krishnagk/testrebaseone/-/merge_requests/new?merge_request%5Bsource_branch%5D=f-two
remote: 
To https://gitlab.com/krishnagk/testrebaseone.git
* [new branch]      f-two -> f-two
  1. Create a merge request to merge the f-two branch into the master branch

Request to merge f-two into master

Merged by Krishna Kurtakoti 17 minutes ago (Jun 2, 2021 8:09am GMT+0530)17 minutes ago The changes were merged into master with 044f2ae0

enter image description here

After successful merge, checkout the local master branch and take a pull from remote master.

krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git pull origin master
Username for 'https://gitlab.com': krishnagk
Password for 'https://[email protected]': 
From https://gitlab.com/krishnagk/testrebaseone
 * branch            master     -> FETCH_HEAD
Already up to date.
  1. Checkout the branch new-branch-one
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git checkout new-branch-one
Switched to branch 'new-branch-one'
  1. The problem is arising in this step when I want to do the rebase master being on the branch new-branch-one
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: commit D
Using index info to reconstruct a base tree...
M   todo
Falling back to patching base and 3-way merge...
Auto-merging todo
CONFLICT (content): Merge conflict in todo
error: Failed to merge in the changes.
Patch failed at 0001 commit D
hint: Use 'git am --show-current-patch' to see the failed patch
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
  1. After successful resolving of the conflicts, we do git status
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git status
rebase in progress; onto 044f2ae
You are currently rebasing branch 'new-branch-one' on '044f2ae'.
  (all conflicts fixed: run "git rebase --continue")

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   todo
  1. Experimental steps:
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git commit -m 'rebase'
[detached HEAD c83a6ff] rebase
 1 file changed, 2 insertions(+)
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git rebase --continue
Applying: commit D
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

@torek Thanks. I tried what you have suggested and below are the results:

krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git status
rebase in progress; onto 044f2ae
You are currently rebasing branch 'new-branch-one' on '044f2ae'.
  (all conflicts fixed: run "git rebase --continue")

nothing to commit, working tree clean
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git rebase --continue
Applying: commit D
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
krishna@krishna-Lenovo-G50-70:~/r/testrebaseone$ git rebase --skip
Applying: commit E
Using index info to reconstruct a base tree...
M   todo
Falling back to patching base and 3-way merge...
Auto-merging todo

Upvotes: 0

Views: 300

Answers (1)

Mark Bramnik
Mark Bramnik

Reputation: 42491

Man, your question is too much detailed. It looks like it boils down to the merge conflict that you encounter during the step 7.

You’ve modified the todo file in both branches, and git doesn’t know which version to pick, or maybe it should partially pick the change from one branch and add the changes from another, and what to do with the common part? Git doesn’t know how to answer this kind of questions, so it leaves it to you to understand what to do.

So bottom line you can type after step 7 git status and you’ll see that it in-process of rebasing and there are conflicts to resolve

You resolve the conflicts in the file (I usually do it in IDE, like those of JetBrains for example because they provide a good UI) but you can use any other ide or do it yourself,

In any case, once you resolve the conflicts and you get to the version you would like to preserve, you type git add . (or git add todo if you want to be specific) and then git rebase --continue (double hyphen) GIT will continue the rebase and make it to the point when you have a “clean status”.

Upvotes: 1

Related Questions