Reputation: 5737
So I'm in branch A. I do git pull origin master
and it tells me I'm up to date. I checkout master and I see File 1. I checkout branch A and File 1 is not there even though it tells me I'm up to date.
I checkout master again, create branch B. I checkout branch B and File 1 is there. I do git pull origin A and File 1 is no longer there. Same happens if I reverse the process and create B then push to B from A. So at this point I can't push to master because it appears I will delete much needed files but I can't pull and get them.
I have changes in branch A I want and I haven't deleted any files. For some reason it's acting like I deleted File 1 and even if I deleted it accidentally, why wouldn't a pull return it for me?
Is there a way I can tell git to give me all missing files from one branch to another?
Upvotes: 0
Views: 1607
Reputation: 333046
According to your description, it sounds like you deleted File1 in branchA. When pulling from origin/master
, Git sees that nothing happened to File1 in origin/master
, and that the file has been deleted in branchA, so when it merges them, that merges cleanly as deleting File1. Remember, a "pull" is just a way of fetching and automatically merging two branches.
If you want to restore File1 on branchA, there are a couple of options. If you haven't pushed it yet, one option is just to rebase and get rid of the removal. Or, you can run git checkout master -- File1
to check out the version of File1 that is present on master, and add that to a commit on branchA to add it back.
If you want to compare branches, just git diff
should suffice. If you want to just see which files have been added, removed, or changed, you can use git diff --stat
. Try doing git diff --stat master origin/master
to see what has changed between your master branch and origin/master
.
It can also be useful to visualize these changes with gitk
or git log --graph --decorate --oneline
. gitk master...origin/master
, or gitk origin/master...branchA
can help you see what commits are in one of those branches but not the other.
Upvotes: 1
Reputation: 17586
One of your commits in branch A deletes the file (or files) you care about. Since you say you can't push branch A because of this, I am assuming you haven't published your history, and would like to rewrite it.
To find the commit which deletes the file, try:
git log --stat master..A
then try:
git checkout A
git rebase -i master
and mark the commit that you would like to fix for editing with 'e'.
Then use look at the state of that commit:
git status
And undo the removal of those files:
git reset file-that-was-deleted
git checkout -- file-that-was-deleted
And resume the rebase:
git rebase --continue
Upvotes: 0