如何在我的工作副本中排除非指数的变更?
当前回答
没有一个解决方案工作,如果你只是改变了文件的许可(这是DOS/Windoze)
Mon 23/11/2015-15:16:34.80 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: .gitignore modified: LICENSE.txt modified: TODO.txt modified: codeStyle.xml modified: pom.xml modified: version.pl no changes added to commit (use "git add" and/or "git commit -a") Mon 23/11/2015-15:16:37.87 C:\...\work\checkout\slf4j+> git diff diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE.txt b/LICENSE.txt old mode 100644 new mode 100755 diff --git a/TODO.txt b/TODO.txt old mode 100644 new mode 100755 diff --git a/codeStyle.xml b/codeStyle.xml old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 diff --git a/version.pl b/version.pl old mode 100644 new mode 100755 Mon 23/11/2015-15:16:45.22 C:\...\work\checkout\slf4j+> git reset --hard HEAD HEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore Mon 23/11/2015-15:16:47.42 C:\...\work\checkout\slf4j+> git clean -f Mon 23/11/2015-15:16:53.49 C:\...\work\checkout\slf4j+> git stash save -u Saved working directory and index state WIP on SLF4J_1.5.3: 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore HEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore Mon 23/11/2015-15:17:00.40 C:\...\work\checkout\slf4j+> git stash drop Dropped refs/stash@{0} (cb4966e9b1e9c9d8daa79ab94edc0c1442a294dd) Mon 23/11/2015-15:17:06.75 C:\...\work\checkout\slf4j+> git stash drop Dropped refs/stash@{0} (e6c49c470f433ce344e305c5b778e810625d0529) Mon 23/11/2015-15:17:08.90 C:\...\work\checkout\slf4j+> git stash drop No stash found. Mon 23/11/2015-15:17:15.21 C:\...\work\checkout\slf4j+> git checkout -- . Mon 23/11/2015-15:22:00.68 C:\...\work\checkout\slf4j+> git checkout -f -- . Mon 23/11/2015-15:22:04.53 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: .gitignore modified: LICENSE.txt modified: TODO.txt modified: codeStyle.xml modified: pom.xml modified: version.pl no changes added to commit (use "git add" and/or "git commit -a") Mon 23/11/2015-15:22:13.06 C:\...\work\checkout\slf4j+> git diff diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE.txt b/LICENSE.txt old mode 100644 new mode 100755 diff --git a/TODO.txt b/TODO.txt old mode 100644 new mode 100755 diff --git a/codeStyle.xml b/codeStyle.xml old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 diff --git a/version.pl b/version.pl old mode 100644 new mode 100755
修复这一点的唯一方法是手动重新设置已更改的文件中的权限:
Mon 23/11/2015-15:25:43.79 C:\...\work\checkout\slf4j+> git status -s | egrep "^ M" | cut -c4- | for /f "usebackq tokens=* delims=" %A in (`more`) do chmod 644 %~A Mon 23/11/2015-15:25:55.37 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 nothing to commit, working directory clean Mon 23/11/2015-15:25:59.28 C:\...\work\checkout\slf4j+> Mon 23/11/2015-15:26:31.12 C:\...\work\checkout\slf4j+> git diff
其他回答
没有一个解决方案工作,如果你只是改变了文件的许可(这是DOS/Windoze)
Mon 23/11/2015-15:16:34.80 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: .gitignore modified: LICENSE.txt modified: TODO.txt modified: codeStyle.xml modified: pom.xml modified: version.pl no changes added to commit (use "git add" and/or "git commit -a") Mon 23/11/2015-15:16:37.87 C:\...\work\checkout\slf4j+> git diff diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE.txt b/LICENSE.txt old mode 100644 new mode 100755 diff --git a/TODO.txt b/TODO.txt old mode 100644 new mode 100755 diff --git a/codeStyle.xml b/codeStyle.xml old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 diff --git a/version.pl b/version.pl old mode 100644 new mode 100755 Mon 23/11/2015-15:16:45.22 C:\...\work\checkout\slf4j+> git reset --hard HEAD HEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore Mon 23/11/2015-15:16:47.42 C:\...\work\checkout\slf4j+> git clean -f Mon 23/11/2015-15:16:53.49 C:\...\work\checkout\slf4j+> git stash save -u Saved working directory and index state WIP on SLF4J_1.5.3: 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore HEAD is now at 8fa8488 12133-CHIXMISSINGMESSAGES MALCOLMBOEKHOFF 20141223124940 Added .gitignore Mon 23/11/2015-15:17:00.40 C:\...\work\checkout\slf4j+> git stash drop Dropped refs/stash@{0} (cb4966e9b1e9c9d8daa79ab94edc0c1442a294dd) Mon 23/11/2015-15:17:06.75 C:\...\work\checkout\slf4j+> git stash drop Dropped refs/stash@{0} (e6c49c470f433ce344e305c5b778e810625d0529) Mon 23/11/2015-15:17:08.90 C:\...\work\checkout\slf4j+> git stash drop No stash found. Mon 23/11/2015-15:17:15.21 C:\...\work\checkout\slf4j+> git checkout -- . Mon 23/11/2015-15:22:00.68 C:\...\work\checkout\slf4j+> git checkout -f -- . Mon 23/11/2015-15:22:04.53 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: .gitignore modified: LICENSE.txt modified: TODO.txt modified: codeStyle.xml modified: pom.xml modified: version.pl no changes added to commit (use "git add" and/or "git commit -a") Mon 23/11/2015-15:22:13.06 C:\...\work\checkout\slf4j+> git diff diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE.txt b/LICENSE.txt old mode 100644 new mode 100755 diff --git a/TODO.txt b/TODO.txt old mode 100644 new mode 100755 diff --git a/codeStyle.xml b/codeStyle.xml old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 diff --git a/version.pl b/version.pl old mode 100644 new mode 100755
修复这一点的唯一方法是手动重新设置已更改的文件中的权限:
Mon 23/11/2015-15:25:43.79 C:\...\work\checkout\slf4j+> git status -s | egrep "^ M" | cut -c4- | for /f "usebackq tokens=* delims=" %A in (`more`) do chmod 644 %~A Mon 23/11/2015-15:25:55.37 C:\...\work\checkout\slf4j+> git status On branch SLF4J_1.5.3 nothing to commit, working directory clean Mon 23/11/2015-15:25:59.28 C:\...\work\checkout\slf4j+> Mon 23/11/2015-15:26:31.12 C:\...\work\checkout\slf4j+> git diff
而不是放弃更改,我将我的远程重新设置到原始。 注意 - 这个方法是完全恢复您的文件夹到复制文件夹。
所以我这样做是为了确保他们在我 git 重新设置时不会坐在那里(后来 - 排除 gitignores 在 起源 / 品牌名称)
注意: 如果您想要保持尚未跟踪的文件,但不在 GITIGNORE 您可能希望错过此步骤,因为它将删除这些未跟踪的文件未在您的远程存储库中找到(感谢 @XtrmJosh)。
git add --all
然后我
git fetch --all
然后我回到起源。
git reset --hard origin/branchname
就像 RE-Cloning 分支, WHILE 保持所有我的 gitignored 文件在本地和地点。
按下面的用户评论更新: 变量重新设置到用户目前的任何分支。
git reset --hard @{u}
无论你的 repo 是什么状态,你总是可以重新设置到任何以前的承诺:
git reset --hard <commit hash>
这将消除随后发生的所有变化。
当您输入 git 状态时(使用“git checkout -...”来删除工作目录的变更)显示。
上一篇:Git Checkout
因为没有答案表明我所使用的准确选项组合,这里是:
git clean -dxn . # dry-run to inspect the list of files-to-be-removed
git clean -dxf . # REMOVE ignored/untracked files (in the current directory)
git checkout -- . # ERASE changes in tracked files (in the current directory)
以下是使用的 git 清洁选项的在线帮助文本:
D
除未追踪的目录外,除未追踪的文件外,除未追踪的目录外,除未追踪的目录外,除非由另一个 Git 存储库管理,则不会默认删除。
x
不要使用从.gitignore (每个目录) 和 $GIT_DIR/info/exclude 阅读的默认忽略规则,但仍然使用与 -e 选项提供的忽略规则. 这允许删除所有未追踪的文件,包括构建产品。
N
实际上不要删除任何东西,只是显示会做什么。
F
如果 Git 配置变量 clean.requireForce 不被设置为虚假, Git clean 将拒绝删除文件或目录,除非 -f、 -n 或 -i. Git 将拒绝删除.git 子目录或文件中的目录,除非另一个 -f 被提供。
推荐文章
- Visual Studio Code: .git文件夹/文件隐藏
- “node_modules”文件夹应该包含在git存储库中吗
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 跟踪所有远程git分支作为本地分支