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!
Git does not apply deleted files when merging an old branch into the 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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With