简体   繁体   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")

I do not know what (new commits) does mean?我不知道(新提交)是什么意思? I do not want to commit these files.我不想提交这些文件。 I tried to do我试着做

$ git checkout -- . 

What if i put config/puppet/* to gitignore file then updated the cache as following如果我把 config/puppet/* 放到 gitignore 文件然后更新缓存如下

$ git rm --cached -r . 

will this delete these files from repo.这会从 repo 中删除这些文件吗? after pushing or merging with other branches?在与其他分支推送或合并之后?

git reset is the command to unstage file from git. git reset是从 git 取消暂存文件的命令。

After unstaging the file, you can confirm it by git status command as well.取消暂存文件后,您也可以通过git status命令进行确认。

If the directories under config/puppet/modules/ are submodules, try如果config/puppet/modules/下的目录是子模块,试试

$ git submodule update

which worked for me.这对我有用。 See https://stackoverflow.com/a/14422494/5794048https://stackoverflow.com/a/14422494/5794048

If you want to save the modification for later use, just stash them with如果你想保存修改以备后用,只需将它们隐藏起来

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

If you want to drop the modification, just do如果你想放弃修改,就做

git add . && git reset --hard HEAD


Attach: to show what you have stashed with git stash list , to apply the stash with git stash pop附加:显示您使用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