【问题标题】:Git: how to unstage file changes (new commits)Git:如何取消暂存文件更改(新提交)
【发布时间】:2016-07-05 03:28:55
【问题描述】:
mohamed@mohamed:~/Projects/skyrocket$ git status 
On branch dev/SMMWEB-36
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:   config/puppet/modules/apt (new commits)
    modified:   config/puppet/modules/augeas (new commits)
    modified:   config/puppet/modules/concat (new commits)
    modified:   config/puppet/modules/elasticsearch (new commits)
    modified:   config/puppet/modules/file_concat (new commits)
    modified:   config/puppet/modules/git (new commits)
    modified:   config/puppet/modules/php (new commits)
    modified:   config/puppet/modules/postgresql (new commits)
    modified:   config/puppet/modules/redis (new commits)
    modified:   config/puppet/modules/stdlib (new commits)
    modified:   config/puppet/modules/vcsrepo (new commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .idea/copyright/
    config/puppet/modules/blackfire/
    config/puppet/modules/inifile/
    dump.rdb
    keys.dev.pub
    keys.tags.pub

no changes added to commit (use "git add" and/or "git commit -a")

我不知道(新提交)是什么意思? 我不想提交这些文件。 我试着做

$ git checkout -- . 

如果我把 config/puppet/* 放到 gitignore 文件然后更新缓存如下

$ git rm --cached -r . 

这会从 repo 中删除这些文件吗?推送或合并其他分支后?

【问题讨论】:

    标签: git github version-control


    【解决方案1】:

    我们可以运行命令git reset --hard

    【讨论】:

    【解决方案2】:

    如果你想保存修改以供以后使用,只需将它们隐藏起来

    git add . &amp;&amp; git stash save "info for the modification".

    如果你想放弃修改,就这样做

    git add . &amp;&amp; git reset --hard HEAD


    附上: 显示您使用git stash list 存储的内容,使用git stash pop 应用存储

    【讨论】:

      【解决方案3】:

      如果config/puppet/modules/下的目录是子模块,试试

      $ git submodule update
      

      这对我有用。见https://stackoverflow.com/a/14422494/5794048

      【讨论】:

        【解决方案4】:

        使用“git reset”你可以撤消所有添加 或者使用 git reset file_name 你可以撤消选择添加

        【讨论】:

          【解决方案5】:

          git reset 是从 git 中取消暂存文件的命令。

          取消暂存文件后,您也可以通过git status 命令确认。

          【讨论】:

            【解决方案6】:

            使用git reset 取消暂存文件!

            【讨论】:

            • 这与提及reset的现有答案有何不同?
            猜你喜欢
            • 2012-09-30
            • 2012-08-26
            • 2015-01-09
            • 1970-01-01
            • 2020-12-15
            • 2014-04-03
            • 2019-05-06
            • 2020-11-14
            • 2018-11-22
            相关资源
            最近更新 更多