How smart is git in rebasing in python?

284 Views Asked by At

I'm currently experimenting with git and encountered the following problem. I created a python file with one function called f1 and saved it under main.py and committed it to the master branch. I then created a branch called b1 of that, went back to the master and changed the name of that function to f2 (no other changes). Back in the branch b1 I added a second function called new_function. After that I tried to rebase b1 onto master.

I was surprised to see that there was a conflict. Why isn't git seeing that I simply changed the name of f1 to f2 in the master?

Am I doing anything wrong? Any suggestions are appreciated.

2

There are 2 best solutions below

3
On

Git - like almost any other VCS - does not know symanitcs of the tracked content, so it cannot guess what is conflicting and what not. If you merge or rebase two histories that both changed the same file, this is a conflict and you have to resolve it. Use a propert tool for this (like P4Merge, the best free diff / merge tool I know) and it is easy as pie to resolve the conflict or in your case see that there maybe is not even a real conflict.

9
On

You are not doing anything wrong. Git is simply preventing any potential loss of your work. At this point, since function f1 has been changed to f2 in your master branch - your branch b2 still refers to it as f1. So, when you do git rebase, git will simply ask you "so what name do you want it to be f1,f2 or something else.