簡體   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