如何在我的工作副本中排除非指数的变更?


当前回答

当你想将一个字符转移到另一个人时:

# add files
git add .  
# diff all the changes to a file
git diff --staged > ~/mijn-fix.diff
# remove local changes 
git reset && git checkout .
# (later you can re-apply the diff:)
git apply ~/mijn-fix.diff

[编辑] 如评论,可以命名 stashes. 好吧,如果你想分享你的 stash ;)

其他回答

cd path_to_project_folder  # take you to your project folder/working directory 
git checkout .             # removes all unstaged changes in working directory

要排除工作目录中的变化,使用 git checkout -- <file> -- 意味着当前分支参考的变化:-

https://www.baeldung.com/git-discard-unstaged-变更

作为一个提醒,更新的版本的 git 有恢复命令,这也是一个建议,当你在更改文件时输入 git 状态时:

(使用“吉特添加......”更新什么将被承诺)

(使用“git restore...”来删除工作目录的更改)

所以 git'restore' 是这个问题的现代解决方案. 在输入 'git status' 后,从 git 阅读建议总是很好的想法 :-)

它甚至在常见的 git 许可之外的目录中工作。

sudo chmod -R 664 ./* && git checkout -- . && git clean -dfx

最近发生在我身上

如果您想恢复未完成的文件,请使用 git restore --staged。