Reputation: 2720
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
Upvotes: 0
Views: 217
Reputation: 3956
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.
Upvotes: 3