Home > Software design >  Git rebase not applying to latest commit of a branch
Git rebase not applying to latest commit of a branch

Time:01-14

I am facing a weird issue during git rebase

I have a branch called Networkconfigs with two commits like C1 & C2, Now I want to rebase with master. conflicts are raising only on top of C1 changes. I am unable to see C2 changes during conflict resolution.

command used for rebase at Networkconfigs: git rebase master

branch Networkconfigs
At C1 commit I have a file : Sample.txt
At C2 commit I have replace the Sample.txt with Result.txt

during conflict resolution I can see the Sample.txt in Networkconfigs instead of Result.txt. But If I switched Networkconfigs C2 changes are present(i.e Result.txt existed)

git log -5 --graph --oneline NetworkConfigFiles
* df3acf356 (origin/NetworkConfigFiles, NetworkConfigFiles) additional changes
* d7bb7a5dc Incorporate the review comments
* 5243f782f create Network config files
* fb372f921 Incrementing build version to 2.0.2495.0 ***NO_CI***
* 89ce8a232 Incrementing build version to 2.0.2494.0 ***NO_CI***

conflicts are raising w.r.t 5243f782f

CodePudding user response:

Rebase changes are applied one at a time in an orderly fashion so if C2 is after C1 in history (actually, if C1 is listed first in the rebase... given that their order can be shuffled around if using interactive), sure, you won't see C2's changes on HEAD until you have gone over applying C1 changes.

Suppose your branches look like this right now:

A <- B <- C <- D <- E <- F <- (main)
          ^
           \- G <- H <- I <- (some-branch)

Now, suppose that you run this:

git checkout some-branch
git rebase main

That will mean that G, H and I (or equivalents, rather) will be on top of F, right? But it's not like magic happens. Git has to apply changes one at a time, so.... if there are conflict when applying H, and you take a look at the branch that you are on at the moment, you will find that it looks like this:

A <- B <- C <- D <- E <- F <- G' <- (HEAD)
          ^              ^
          |               \- (main)
           \- G <- H <- I <- (some-branch)

Notice how on HEAD, I is not applied yet, so do not expect to see code from that commit where you are standing.

  • Related