Git; code disappeared after merge
changes which were committed at some point are hard to lose completely. Try running 'git reflog' and see if you can spot the commit you've lost. Then you can merge it into the current branch by running "git merge [SHA1 of your lost commit]".
Because your history has already been pushed, the best way is to make a new commit. Otherwise, you run the risk of losing other code and messing up everyone's repos.
Since you know where the commit that last has the function, you can git checkout 48d60a03 -- <name of file with function>
. Then you can commit the old/new file with the function.
As there are likely to be other changes in the file, you will probably want to git reset
to unstage the file and use git add -p
to only add the changes for the function that you are looking for.
For preventing this from happening, my recommendation is to get a comprehensive test suite that you can run after completing a merge. That can help minimize the chances that code will be lost as tests will fail.
Apparently (see this question), git show
is not the right tool to use to have a clear view of the changes introduced by a merge commit.
Use git diff
. The merge commit has two parents :
* 8ac6131 (M) Merge branch 'B'
|\
| * 5a53959 (B) two
|
* 7cb5a06 (A) one
Use git diff A M
and git diff B M
to view the differences between the merge commit and either of its parent. You should see your missing function there.