繁体   English   中英

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

[英]Git: how to unstage file changes (new commits)

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 reset是从 git 取消暂存文件的命令。

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

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

$ git submodule update

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

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

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

如果你想放弃修改,就做

git add . && git reset --hard HEAD


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

使用git reset取消git reset文件!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM