Git:如何取消暂存文件更改(新提交)

4
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")

我不知道“new commits”是什么意思? 我不想提交这些文件。 我试图执行以下操作:

$ git checkout -- . 

如果我将config/puppet/*放入gitignore文件中,然后按照以下方式更新缓存,会发生什么?
$ git rm --cached -r . 

这样做会在推送或合并到其他分支后从版本库中删除这些文件吗?
6个回答

0
如果您想将修改保存以备后用,只需使用以下命令进行隐藏: git add . && git stash save "info for the modification"
如果您想放弃修改,请执行以下操作: git add . && git reset --hard HEAD

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


0

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

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


0

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

3
--hard中,--hard之间不应有空格。否则它将被视为git reset -- <path>。请参考--hardgit reset -- <path> - Gino Mempin

-1

使用 git reset 命令取消暂存文件!


这与现有提到“reset”的答案有何不同? - mustaccio

-1

使用 "git reset" 可以撤销所有的添加,或者使用 git reset 文件名可以撤销指定的添加


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接