代码之家  ›  专栏  ›  技术社区  ›  Koobz

使用git add--patch以交互方式删除Hunk

git
  •  10
  • Koobz  · 技术社区  · 16 年前

    很好

    偶尔我会遇到一个可能是错误日志语句的大块头,一个额外的换行符(通常是删除前面提到的日志语句)——实际上我宁愿完全删除它。

    我不想登台表演,我还想简单地删除正在讨论中的帅哥,而它就在我面前(而不是跳回到我的编辑那里再试一次)。我也想对我的工作文件应用更改。

    有办法做到这一点吗?


    这一点,与该建议相结合 hash

    git add 中国的关注点分离。奥托,那太方便了;P我听起来像我的老板;)

    3 回复  |  直到 16 年前
        1
  •  5
  •   Xentac    16 年前

    比使用重置硬头更好的是,在提交了所有有效的大块文件之后,您只需git签出文件,将其重置为当前分支中记录的内容。这样就不会影响任何其他文件。

        2
  •  2
  •   Herman van Rink    10 年前

    on the Git mailinglist 响应功能请求。

    # start from N-commit worth of change, debug and WIP
    git stash save -p debug ;# stash away only the debugging aid
    # now we have only N-commit worth of change and WIP
    git stash save -p wip ;# stash away WIP
    
    git add -p ;# prepare the index for the next commit
    git stash save -k ;# save away the changes for later commits
    
    git commit
    
        3
  •  0
  •   hash    16 年前

    您可以向索引添加任何您想要的内容,提交,然后重置硬头,然后索引中没有的内容将丢失。