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

时间:2016-03-18 11:34:29

标签: git github version-control

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中删除这些文件。推或合并其他分支后?

6 个答案:

答案 0 :(得分:1)

使用git reset 取消暂存文件!

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

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

答案 3 :(得分:0)

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

$ git submodule update

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

答案 4 :(得分:0)

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

答案 5 :(得分:0)

如果您想保存修改以供以后使用,只需将其隐藏

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

如果要删除修改,只需执行

git add . && git reset --hard HEAD


附加:   显示您用git stash list藏匿的东西,应用git stash pop

藏匿的东西