3

I have a local / remote branchA that I am only working on. BranchA was created from develop branch. I have made somewhere like a dozen commits to it. Now I am at a stage where I want to pull all the changes from develop that were made in the meantime, so that BranchA is containing all the latest changes from develop, so I can test it.

I have tried to rebase develop onto BranchA, but it is a bit difficult to resolve conflicts. What happens is that there is a FileA that was changed in developer branch, but I have also changed this file in lot of my commits (lets say 8). So it seems that git is asking me to resolve conflict for this file 8 times, while I would like it to ask me only for latest version.

So, what are my options here? Should I merge all my 12 commits into 1, and then try to rebase? How would I correctly do this?

piet.t
  • 11,718
  • 21
  • 43
  • 52
Goran
  • 6,328
  • 6
  • 41
  • 86

2 Answers2

1

I'm not sure what the best course of action here is (generally that's fairly preference/policy driven), but if you want to do a rebase and squash all the commits together into one, you can do:

git checkout develop
git rebase -i BranchA

which will open up an editor with a line for each commit on develop that doesn't exist in BranchA.

There are instructions in this editor that outline what you can do, but in this case you can:

  • leave the topmost (first) commit action as pick
  • change all the other commit actions to squash or fixup

The difference between squash and fixup is that squash will concatenate all the commit messages of the squashed commits together and allow you to edit this commit message, whereas fixup will just use the commit message of the commit that the others are "fixed-up" onto, without allowing you to edit it.

My preference is generally to use squash to keep at least some semblance of the commit history, but it all depends on how polished my branch has been up till that point.

msbit
  • 4,152
  • 2
  • 9
  • 22
1

I have tried to rebase develop onto BranchA

No: you need to rebase your branch onto the common branch develop

git checkout BranchA
git rebase develop

If a similar merge conflict appears many time, git rerere can help.

Another approach would be simply to merge develop into BranchA.

The point is that I want to add the change in FileA from new develop commit, to latest version for FileA from my BranchA.

For a given file, you can simply checkout it once the rebase is blocked by a conflict:

 git checkout develop -- FileA
 git rebase --continue

That way, the resolution is very quick (since you override FileA with the one from the develop branch)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That is what I did, sorry for wrong expression. The point is that I want to add the change in FileA from new develop commit, to latest version for FileA from my BranchA. I do not want to resolve conflicts for each commit to this file that I made in BranchA, only between 1st and last. Will merge action make changes to develop branch too? Or can I safely say that any git action will make changes only on the ckecedout branch? – Goran Aug 03 '18 at 09:14
  • @Goran I have edited the answer to address your comment. – VonC Aug 03 '18 at 09:17