【问题标题】:Overwrite single file in my current branch with the same file in the main branch?用主分支中的相同文件覆盖当前分支中的单个文件?
【发布时间】:2012-11-30 14:37:55
【问题描述】:

假设我有两个分支 - masterredesign。我将如何用 master 中的文件覆盖我重新设计分支中的文件 default.aspx.cs

我找到了this question,但它似乎讨论了如何将文件恢复到同一分支中的先前版本。我也考虑过使用merge,但我不想合并,我想覆盖。有什么建议吗?

【问题讨论】:

    标签: git


    【解决方案1】:

    git checkout master path/to/default.aspx.cs

    在执行此操作之前,您可能必须:git checkout redesign

    所以,只需 git checkout FROM_BRANCH_NAME path/to/file

    【讨论】:

    • 有没有办法用原始本地文件的内容来扭转这种变化?
    • 使用git checkout,您将覆盖本地更改,而无法恢复这些更改。据我所知。您可以尝试git show :path/to/file(带有 : 前缀)。但这假设您之前已经暂存了您的文件。见gitrevisions
    • 对我来说git checkout origin/master <file> 工作。 master 没用。
    【解决方案2】:

    从另一个分支覆盖一个分支中的文件,即masterredesign 做(当redesign 是当前分支时)

    git checkout master ./path_to_file/default.aspx.cs

    git checkout branch_name ./path_to_file/file_name.[file_extension]

    了解更多关于命令 checkout git checkout 文档

    【讨论】:

      猜你喜欢
      • 2023-01-14
      • 1970-01-01
      • 2010-11-20
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多