Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing files after git merge

Tags:

git

git-merge

Some weeks ago I create a feature branch, I'm developing in. There are severals commits and some new files as well. I can change from master branch to my development branch and versa vice and everything is fine.

Today I tried to merge my branch back to the master branch. Therefore I changed to master and called

git merge mydevbranch

which resulted in several merge conflicts. i resolved these conflicts with

git mergetool

But now, I realized, there are some files missing within the result I have to commit. So there are two questions: Shouldn't be there all merged items on my hard disk after merging? How can I proceed to get the real merge result (master + my feature branch).

like image 835
Martin H. Avatar asked Jan 21 '14 16:01

Martin H.


People also ask

Does git merge remove files?

If you remove a file in one branch, the merge will remove it in the target branch too.

Does git merge keep history?

In the Conceptual Overview section, we saw how a feature branch can incorporate upstream changes from main using either git merge or git rebase . Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .

Does git merge add new files?

git merge incorporate all changes from test to master , i.e. the changed, added and removed files in test will be changed, added or removed in master .

How do I restore my last merge?

You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.


3 Answers

After some investigation I found the following. The file was added by me on master before creating the branch (that's why it was in my dev-branch). But now the crazy thing: The file was deleted in master afterwards by a colleague, but without any status information. Status log only shows the creation of the file. So the merge was correct, but due to the missing status information it was not comprehensible to me.

like image 156
Martin H. Avatar answered Oct 26 '22 22:10

Martin H.


Check if there is nothing in stash

git stash pop

For new files, please make sure you add them first (git status should list them)

git add

The best docs about Git at all, including branches: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

like image 28
Marcin Barylski Avatar answered Oct 26 '22 21:10

Marcin Barylski


For your first question: Shouldn't be there all merged items on my hard disk after merging?

I do a experiment on my own environment. It has the same effect as you has. So my conclusion is that, the file deleted in your master branch will not come back in your master branch if you merge the develop branch which has that same file.

I think this makes sense. Let's assume that you had deleted lots of unwanted files in the master branch and commit those removals. Then you merge the develop branch who has all those unwanted files. If all those unwanted files are 'added' into the master branch again, you may be upset to see that happen because you have to take time to delete them again.

like image 1
Dong Avatar answered Oct 26 '22 23:10

Dong