Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git master branch simply does not have new files after merge

Tags:

git

Suppose I have 2 branches, master and other.

I go in the other branch, add 2 files, commit and push.

Now I go into the master branch, add files to a different directory, and commit them. Then I merge other.

The problem is that the files I added in other are not showing up. Git says it is up-to-date, but its not! Files are missing.

How can I force master to add the files in other or somehow manually add them?

Edit for Karl:

I did the following to the best of my knowledge, although the changes that are not showing up are several weeks old. I just realized they weren't there today.

$ git branch
*other
master
$ git add .
$ git commit -m 'cool new features'
$ git push origin other
$ git checkout master
$ git merge other
$ git add .
$ git commit -m 'merged cool new features from other'
$ git push origin master

I go on Github, and the files aren't there. Other files were committed and show up, but two folders do not have matching content. The files exist in other but not in master. To clarify, the files were not new. But I thought that merging would at least copy files to master if they dont exist!

like image 895
AJcodez Avatar asked Nov 29 '12 02:11

AJcodez


People also ask

Does merging branches delete files?

Git does not apply deleted files when merging an old branch into the master.

Does merging master into branch change master?

git merge master will update your current branch with the changes from your local master branch, the state of which will be that of when you last pulled while on that branch.

What happens to a branch when you merge?

When you perform a merge, you effectively merge one branch into another—typically a feature branch or bug fix branch into a main branch such as master or develop. Not only will the code changes get merged in, but also all the commits that went into the feature branch.

Does a branch disappear after merge?

There's no problem in deleting branches that have been merged in. All the commits are still available in the history, and even in the GitHub interface, they will still show up (see, e.g., this PR which refers to a fork that I've deleted after the PR got accepted).


1 Answers

Like this:

karl@Bielefeldt-Server:~/stackoverflow$ git init .
Initialized empty Git repository in /home/karl/stackoverflow/.git/
karl@Bielefeldt-Server:~/stackoverflow$ touch common_file_a
karl@Bielefeldt-Server:~/stackoverflow$ touch common_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git add .
karl@Bielefeldt-Server:~/stackoverflow$ git commit -m "commit common files"
[master (root-commit) 89a5cd0] commit common files
 0 files changed
 create mode 100644 common_file_a
 create mode 100644 common_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git checkout -b other
Switched to a new branch 'other'
karl@Bielefeldt-Server:~/stackoverflow$ mkdir other
karl@Bielefeldt-Server:~/stackoverflow$ touch other/other_file_a
karl@Bielefeldt-Server:~/stackoverflow$ touch other/other_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git add .
karl@Bielefeldt-Server:~/stackoverflow$ git commit -m "commit other files"
[other 9c7409c] commit other files
 0 files changed
 create mode 100644 other/other_file_a
 create mode 100644 other/other_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git checkout master
Switched to branch 'master'
karl@Bielefeldt-Server:~/stackoverflow$ touch master_file_a
karl@Bielefeldt-Server:~/stackoverflow$ touch master_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git add .
karl@Bielefeldt-Server:~/stackoverflow$ git commit -m "commit master files"
[master 3558768] commit master files
 0 files changed
 create mode 100644 master_file_a
 create mode 100644 master_file_b
karl@Bielefeldt-Server:~/stackoverflow$ ls
common_file_a  common_file_b  master_file_a  master_file_b
karl@Bielefeldt-Server:~/stackoverflow$ git merge other
Merge made by the 'recursive' strategy.
 0 files changed
 create mode 100644 other/other_file_a
 create mode 100644 other/other_file_b
karl@Bielefeldt-Server:~/stackoverflow$ ls
common_file_a  common_file_b  master_file_a  master_file_b  other
karl@Bielefeldt-Server:~/stackoverflow$ ls other
other_file_a  other_file_b

If you're getting different results, you're either missing a step, putting an extra step somewhere, or you're getting some sort of error you're not telling us about, like a merge conflict. We have no way of knowing why something so basic isn't working for you unless you post the exact commands and output you're getting, like I did above.

like image 59
Karl Bielefeldt Avatar answered Sep 24 '22 15:09

Karl Bielefeldt