Shrayas
Shrayas

Reputation: 6984

git merge confusion

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!

Upvotes: 0

Views: 441

Answers (3)

John Fisher
John Fisher

Reputation: 22721

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.

Upvotes: 1

Maneesh
Maneesh

Reputation: 1

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

Upvotes: 0

kelloti
kelloti

Reputation: 8941

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

Upvotes: 1

Related Questions