0

I've switched the branch that I was working from 'master' to a 'stable' branch, made my modifications and commited/pushed to that branch. Switched back to 'master' and started to implement a new feature to the software. But when I tried to add my modifications, only the files that was modified or deleted appeared to be added to the repository. The new ones that I've created simply didn't show up!

So I copied all the files to a new location in my computer, switched the branch to the 'stable' again and for my surprise there was my new files! I deleted the files to make sure that no modification was made in that branch, switched back to 'master', copied the files from my backup and no new file appeared.

I've already made this a thousand times, and this was the first time that this happened. I use SourceTree, but for this I've tried the git bash too (which I don't have much knowledge about).

What happened? Why my new files are 'attached' to the 'stable' branch? How can I fix this?

Thanks in advance.

Update:
I've made a clone of the same repository in another folder to see if things work, but I had no success. The problem still happens.

4

3 回答 3

1

From my understanding of your question, you have modifed, added and committed files on one branch (stable) and when you switch to the other branch(master), you are not able to find the changes in your master branch.

For resolving that, you need to merge your branch stable into branch master. git tracks changes to tracked files against each branch, and to see changes made to one branch in another branch, you need to explicitly tell it to merge those changes.

Assuming all your code is working code in both the branches and you have already stashed your new changes (using git stash), you can merge your stable branch into master branch using

git checkout master
git merge stable

This might throw in some merge conflicts if you have further worked upon and committed some common files and your branches have diverged, so you may need to resolve those conflicts manually.

EDIT

OP says in his comments that git add . --force worked for him.

That means, one of the .gitignore pattern on master branch is ignoring all the local changes for master branch. I would suggest comaparing (all) the .gitignore files from both the branches with each other and identify which pattern is causing the issue.

From git add man page

The git add command will not add ignored files by default. If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files. Ignored files reached by directory recursion or filename globbing performed by Git (quote your globs before the shell) will be silently ignored. The git add command can be used to add ignored files with the -f (force) option.

于 2013-10-18T03:56:55.777 回答
0

Try to use

git add fileName

command from git bash, for all your new files, when you are on master branch.

于 2013-10-17T19:54:25.957 回答
0

There's a more convenient way to add files to git, if you are using SourceTree. You should simply press the Add or Add/Remove button on the top button bar.

于 2013-10-17T20:12:53.723 回答