0

I want to understand what git looks for when merging with two different code.

When does it delete code or insert

So if I have code

Foo.java (this is my code)

class Foo { void hello(){} void bye(){} void gone(){} } 

Foo.java (the code being fetched and merged)

class Foo{ void hello(){} void wait(){} void bye(){} } 

If I merge the above code, will this

  1. Does it delete gone and bye method?
  2. If there was changes were made inside hello method, does it delete my 'hello' and rewrites it with the fetched hello?
2
  • 1
    Just to say, changes like this does not deserve a new branch, so use rebase instead of merge. Commented Dec 19, 2012 at 13:17
  • What does the common base version of Foo.java look like? Commented Dec 19, 2012 at 14:17

1 Answer 1

3

Firstly, it won't delete bye, it will insert wait() above it. It won't delete gone() unless it existed in the previous revision and had been deleted in the successive revision without you having touched it in between. If you had added gone() yourself (i.e. git received no indication that this should be deleted), then gone() will be found at the bottom of the merged file. Like this:

class Foo{ void hello(){} void wait(){} void bye(){} void gone(){} } 

Secondly, it wouldn't delete your hello, it would just put the changes made into the hello() that already exists.

Remember, if it can't be merged, it will throw a conflict, and you will have to merge it yourself. It doesn't just delete/add things that don't make sense without human input.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.