Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Pull Request no changes but git diff show changes

I have an issue with my branches

Introduction

I have 3 branches on my project : Dev, Main & Staging

On Dev branch we add new features, on Main branch we fix bugs, on Staging we deploy for testing.

When a bug PullRequest is completed on Main branch, we make a PullRequest Main -> Dev** to keep up to date the Dev branch. When a new feature is developed, a PullRequest is complete on Dev branch.

When we want to deploy all the new features, we make a PullRequest Dev -> Main, and then a PullRequest Main -> Staging. Finally we deploy the content of Staging branch

Problem

When I compare manually my branches Dev and Main, I see there are differences : in Dev branch some files appeared in a folder, but it were moved to another folder before in a previous commit on Main branch.

When I make git diff Main..Dev, I see there are same differences than above.

Normally, at this moment, this two branches have to be at the same state. So I made a PullRequest Main -> Dev to give to branch Dev the correct state (Main state) : but it say that there are no changes on my PullRequest.

Question

How can I properly give to Dev branch the current state of my Main branch ?

Thank you

like image 607
Nathan Bruet Avatar asked Feb 26 '26 21:02

Nathan Bruet


1 Answers

What might have happened

As @matt said in the comments, this is probably the result of a previous merge, where the conflict might have been resolved without moving the files. Now, when you merge again, Git thinks it's already handled that renaming so it doesn't have to deal with it. You could confirm this theory by looking at the commit history since the last merge point: are the renames before or after that?

How to merge Main in and force Dev to take the state of Main

If, at this point, you want to throw away the current state of Dev and make it exactly the state of Main, and you want to do with with a merge operation, I would use the ours strategy. I'm not sure you can do this via a PR, you'll probably have to do it on your PC and push, I hope your workflow allows this!

Unfortunately, you cannot directly do git merge -s theirs Main from Dev, that would be too simple. You have to do git merge -s ours Dev from Main to create the merge commit you want on Dev:

git checkout Main
git merge -s ours Dev  # this "merges" Dev in but ignores all its changes
# don't push this!
git checkout Dev
git merge Main  # this should be a fast-forward merge
# now you can push Dev

And you can clean up your sandbox when you're done, by bringing Main back to where it was, since that merge was intended for Dev:

git checkout Main
git reset --hard origin/Main

What if I want the renames from Main, but not lose the other changes in Dev?

In this case I think you will need to do some manual work. If the renames are indeed before the previous merge, and the merge that brought those commits into the history of Dev was resolved without applying the renames, you need to recreate the renames again on the Dev branch, possibly by hand.

I don't imagine you have the option of going back to that earlier merge and redo it correctly, but if you could, that might be the cleanest option.

like image 135
joanis Avatar answered Feb 28 '26 12:02

joanis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!