Adam Ramadhan
Adam Ramadhan

Reputation: 22810

does git merge cause loss files?

lets say i have two branches

  1. master
  2. develop

in master i have something like

index.php
lib/something.php
lib/importantbugfix.php ( newer )

in develop i have something like

index.php
lib/something.php
lib/importantbugfix.php
lib/config.php

i want importantbugfix.php on master to merge on develop, how can we do that?

so i have something like

in master

index.php
lib/something.php
lib/importantbugfix.php ( newer )

in develop

index.php
lib/something.php
lib/importantbugfix.php ( same newer )
lib/config.php

im reading the docs about git merge right now. and i am afraid that when i do a merge it will do like

in master

index.php
lib/something.php

in develop

index.php
lib/something.php
lib/importantbugfix.php ( newer )
lib/config.php

rather then above.

Upvotes: 0

Views: 114

Answers (2)

Resource
Resource

Reputation: 544

Git merge can cause loss of data if your developers don't understand what they're doing. This happened to my (two-person) team yesterday. We use Git Gui on Windows for merges.

Scenario two in the linked article explains this situation in depth. If you're suffering from it you have my sympathy as you're in for a painful merging experience.

http://randyfay.com/content/avoiding-git-disasters-gory-story

Upvotes: 0

wadesworld
wadesworld

Reputation: 13733

No, merge doesn't replace; it combines - thus the name.

There's several ways to accomplish it.

The easiest is:

git checkout develop
git merge master

This will create a merge commit. It will merge the changes you have on master onto the changes you have on develop. If you've changed the same parts of the file in both places, you'll get a merge conflict and will have to tell git which set of changes you want to keep.

Another way is:

git checkout develop
git rebase master

This will unwind any commits you've done on develop since it was last created from/merged with master and update it with all the newer commits on master since that point, essentially "catching up" develop with master. It will then replay the commits you made on develop on top of the now updated commits which came from master. Effectively it makes it look like your develop branch was created from master today and then you made your develop-specific changes.

The result of this is a much cleaner history. The caveat is that you should not do this if the develop branch is shared with others and the commits past the last time it was branched / merged have already been shared.

Upvotes: 1

Related Questions