0

I am using bit bucket for version controlling.I have repository x,which contains two branches 1) master and 2) sub_branch.

I want to delete some file from master branch while merging sub_branch into master branch.

Though I have found the way to delete file : How can I delete a file from git repo?

I have tried with following command:

git checkout master
git rm <my_file>
git commit -m 'delete file'
git merge sub_branch

unfortunately this dosen't work.

My question is I want to delete some file from a branch before I merge other branch with it.

Thanks a lot. please put your comments if you didn't get anything.

Maaz Patel
  • 756
  • 2
  • 7
  • 20

2 Answers2

1

Just remove the file, commit the change and merge the other branch.

git checkout master
git rm <my_file>
git commit -am 'delete file'
git merge sub_branch
hspandher
  • 15,934
  • 2
  • 32
  • 45
  • @MaazPatel By "it didn't work" I suppose the merge ends with a conflict? – Fabien Bouleau Oct 05 '17 at 07:51
  • When I followed those steps , after merging, "git commit -am 'delete file'" this command has been not reflecting on server. and my file has been not removed from repository. – Maaz Patel Oct 05 '17 at 12:43
  • "didn't work"? means after executing all the commands my file has been not removed from server nor that commit has been pushed. Do I need to push my master branch after merging so that it can reflect on server?? – Maaz Patel Oct 05 '17 at 12:50
  • 1
    @MaazPatel You have deleted file locally. Of course you need to push your changes on the remote. – hspandher Oct 05 '17 at 12:57
1

You need to Add (Stage deleted files) the changes before Commit.

$ git checkout master
$ git rm <my_file>

$ git add -A  # staged deleted, modified & new files

$ git commit -m 'delete file'
$ git merge sub_branch

Additional: if conflict happens then Accept the master (ours) changes.

$ git checkout --ours -- .
$ git add -A
$ git commit -m 'Fix conflicts'  
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73