如何从错误合并的分支中删除文件?

时间:2016-12-14 10:31:56

标签: git git-merge

我有两个分支:master和ubuntu。通常我将主人合并到' ubuntu'。 ' Ubuntu的'分支包含主人加自己的' / debian'文件夹,不在主文件夹中。由于错误,我合并了“ubuntu'给主人,带来了'/ debian'文件夹到主人。

我想将它从主程序中删除,但我希望能够将master与ubuntu合并而不会损坏它自己的' / debian'文件夹,当我将主人合并到' ubuntu'试。

我该怎么做? Merge发生在前一段时间,并且有很多提交,因为......

1 个答案:

答案 0 :(得分:0)

只需reset local/master可以replace remote/master historylocal/master

  1. 首先找出last commit before merging ubuntugit log也许是不错的选择。

    $ git checkout master
    
    $ git log --since=1.hour.ago                      # commit-time < 1 hour
    $ git log --since=3.hour.ago --until=1.hour.ago   #  1 hour < commit-time < 3 hour
    $ git log --since=1.day.ago                       # commit-time < 1 day ago
    
  2. 复制commit-sha并将hard-reset您的local-master复制到该提交中:

    # backup master for safety
    $ git branch master.bac           # backup master to master.bac branch
    
    $ git reset --hard <commit-sha>
    $ git push -f origin master       # force push, replace remote/master history with local/master  
    
相关问题