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

如何放弃对git子模块的更改?

  •  15
  • charlax  · 技术社区  · 13 年前

    我更改了git子模块的提交指针:

    % git status
    # On branch fix
    # Your branch is behind 'origin/fix' by 1 commit, and can be fast-forwarded.
    #
    # Changes not staged for commit:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   modified:   app/lib (new commits)
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    

    然而当我这样做的时候 git checkout ,没有任何变化:

    % git checkout -- app/lib && git status
    # On branch fix
    # Your branch is behind 'origin/fix' by 1 commit, and can be fast-forwarded.
    #
    # Changes not staged for commit:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   modified:   app/lib (new commits)
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    

    以下是差异:

    % git diff
    diff --git a/app/lib b/app/lib
    index d670460..83baae6 160000
    --- a/app/web-lib
    +++ b/app/web-lib
    @@ -1 +1 @@
    -Subproject commit d670460b4b4aece5915caf5c68d12f560a9fe3e4
    +Subproject commit 83baae61804e65cc73a7201a7252750c76066a30
    

    知道为什么会发生这种事吗?

    谢谢

    1 回复  |  直到 13 年前
        1
  •  19
  •   Michael Anderson    13 年前

    当子模块中的SHA发生变化时,Git不会自动更新子模块。

    你要么需要 git submodule update 这将使子模块回到期望的SHA, 或 git add app/lib 这将在子模块中将期望的SHA改变为当前值。