czetsuya
czetsuya

Reputation: 5043

Git already up to date error

We have let's say branch integration, where the tested code is committed and then forTesting branch for all the new features (unstable). For some reason on day x, forTesting was accidentally merged to integration without anyone noticing. After that, multiple commits have already happened on both integration and forTesting branch.

Let's say we have branchFeatureX, that was merged to the forTesting branch before the accidental merge. Now when we want to merge this branch to integration we get the "Already up-to-date" error.

How can we resolve this issue without losing the forward commits in integration branch?

Upvotes: 1

Views: 65

Answers (2)

Marina Liu
Marina Liu

Reputation: 38096

Since you merged featureX branch into fortesting branch and then merged fortesting branch into integration branch, that means changes from featureX branch has already introduced into integration branch. So when you merge featureX branch into fortesting branch, git will show Already up-to-date.

And the commit history for now should as the graph below:

                    ...---A---B---C---K---...---L integration
                                     /
...---C---D---G---H---I---J---...---M---...---N  fortesting
               \         /
                E-------F  featureX

And if you want to introduce the changes from featureX into integration branch based on the latest version of integration branch, you can use the command:

# On integration branch
git cherry-pick <latest commit from featureX branch>

As thee command git cherry-pick <commit F> in above example.

And the commit history will look like (commit O apply the changes from featureX branch into integration branch):

                    ...---A---B---C---K---...---L---O integration
                                     /
...---C---D---G---H---I---J---...---M---...---N  fortesting
               \         /
                E-------F  featureX

Upvotes: 1

Romain Valeri
Romain Valeri

Reputation: 21908

If the point where it went wrong is not too far in history, you could consider the following recovery process :

1) Create a fix branch from your master and work on it to be extra safe

2) git log to find the last good commit before the merge where all went awry. Copy or note the commit hash for further use.

3) git reset --hard <commit_hash_you_spotted_as_good>

4) Then, for each of the feature developed since then and you want back, let's consider two possibilities : (at this point you could look at either logs or graphic representation of your tree, but I'd suggest the latter)

a) the branch was created from master BEFORE all went wrong :

--> just merge this feature in fix branch, should be quite straightforward

b) the branch has been created from an already corrupted version of master

--> git log again to note each of the commits on this branch and cherry-pick them back in fix branch with git cherry-pick <commit_id>

4) test everything on your fix branch to confirm all is well again as you wished for

5) then get back on master branch, reset it hard like you did for fix branch (same last good commit), and merge fix branch in

Upvotes: 1

Related Questions