0

I just started using GIT yesterday and i was trying to do something but i think something went wrong somewhere . Let me explain my situation:

I started off with my working directory (master branch) looking like this

 folder1 file1 file2 file3 

I created another branch with the $ git checkout -b X command

After this , i went ahead and deleted all the files that were in the folder rm -r * and then added a few files in , so the working directory became so (this i think i wasn't supposed to do)

 xFile1 xFile2 

Then after some tests and after i arrived at the fact that the branch was stable .. i wanted to perform a merge and so i did

 $ git checkout -b master $ git merge X 

Now , after the merge , my directory (folder1) got removed . What i actually wanted was to bring xFile1 and xFile2 into the master branch.

I'm so confused with this , please help!

6
  • Did you actually commit anything to branch X? Commented Mar 4, 2012 at 5:08
  • yes yes .. the xFile1 and xFile2 were committed to X Commented Mar 4, 2012 at 5:17
  • If you didn't commit the removal of those files, then there should be no problem. You must have also removed those files to produce the symptoms you're describing. Commented Mar 4, 2012 at 5:19
  • Oh i actually did commit the removal of the files :( Commented Mar 4, 2012 at 5:37
  • If you're new to git, I would highly reccomend having a browse through (at least) the first few chapters of the Pro Git book. It explains git concepts very well, and has a bunch of diagrams that greatly helped me to understand what was going on, and how to achieve things that I wanted to do with git. Commented Mar 4, 2012 at 13:57

3 Answers 3

1

You probably should have rebased instead of merging. The rebase is more of what you're trying to express - you have a good code base in X, and you want to add what's in master on top of what you put in X.

If you use git rebase X from master branch, it will play all the commits in master on top of X

Sign up to request clarification or add additional context in comments.

3 Comments

Oh , i understand :) Let me quickly try that and get back to you
Hey @kelloti , i did the rebase and it worked fine except for when it applied the commit from X where i had deleted the folder1 , so i'm losing out on that . Anything i can do about this ? :( @meagar , please look at this ..
@Shrayas I think you're looking for the -i option for git rebase (interactive) book.git-scm.com/4_interactive_rebasing.html
1

Part of your confusion looks like you assumed that merging ignored your delete operation. In fact, when you deleted the files and committed that change, it remembered this. Merging into master then replayed that delete.

6 Comments

Yes . I just realized that now :( So what would be the correct workflow? Isn't one supposed to delete files ? But what if my feature really doesnt depend on those files ?
@Shraya: If you want the files, don't delete them. If you delete them by accident, use <code>git reset</code> or <code>git checkout</code> to retrieve them.
well the files are necessary for the master branch but not for feature X , right ? how about then ? i'm thinking i should've removed them by doing a git rm then?
@Shrayas: How do you develop a product while deleting code that's not relevant to a specific feature? How is removing existing features helping the overall product?
Yes , come to think of it .. that does make sense. Ok so how do fix this now? i need to checkout to say a branch old to the commit before the deletes happened , merge in the new changes from X to old and merge old back into master ?
|
0

Did you create a commit on branch X before coming back to master? In case not , then it can always create mishaps in git.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.