2017-10-05 30 views
0

我使用位桶版本控制。我有存储库x,其中包含两个分支1)主和2)sub_branch。git删除文件,同时imareging

我想从主分支中删除一些文件,同时将sub_branch合并到主分支中。

虽然我已经找到删除文件的方式: How can I delete a file from git repo?

我曾与下面的命令尝试:

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

可惜这这么想的工作。

我的问题是我想在合并其他分支之前从分支中删除某个文件。

非常感谢。如果你没有得到任何东西,请提出你的意见。

回答

1

只要删除文件,提交更改并合并其他分支。

git checkout master 
git rm <my_file> 
git commit -am 'delete file' 
git merge sub_branch 
+0

我试过这种方法,但没有工作 –

+0

你是什么意思的“没有工作”? – hspandher

+0

@MaazPatel通过“它没有工作”我想合并以冲突结束? –

1

你需要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 

附加:如果发生矛盾,然后接受master我们)的变化。

$ git checkout --ours -- . 
$ git add -A 
$ git commit -m 'Fix conflicts'