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


当前回答

只用:

git stash -u

是的,容易。

如果你真的很关心你的<unk>子,那么你可以跟随吉特<unk>子下降,但在那个时候你更好地使用(从Mariusz Nowak):

git checkout -- .
git clean -df

然而,我喜欢 git stash -u 最好的,因为它“排除”所有跟踪和未跟踪的变化在一个命令。 但是 git checkout -. 只排除跟踪的变化, git clean -df 只排除未跟踪的变化... 并输入两个命令是太多的工作:)

其他回答

另一种更快的方式是:

git stash save --keep-index --include-untracked

你不需要包含 - 包括 - 不被吸引,如果你不想仔细了解它。

接下来,你可以用 git stash drop 命令放下这个 stash 如果你愿意。

而不是放弃更改,我将我的远程重新设置到原始。 注意 - 这个方法是完全恢复您的文件夹到复制文件夹。

所以我这样做是为了确保他们在我 git 重新设置时不会坐在那里(后来 - 排除 gitignores 在 起源 / 品牌名称)

注意: 如果您想要保持尚未跟踪的文件,但不在 GITIGNORE 您可能希望错过此步骤,因为它将删除这些未跟踪的文件未在您的远程存储库中找到(感谢 @XtrmJosh)。

git add --all

然后我

git fetch --all

然后我回到起源。

git reset --hard origin/branchname

就像 RE-Cloning 分支, WHILE 保持所有我的 gitignored 文件在本地和地点。

按下面的用户评论更新: 变量重新设置到用户目前的任何分支。

git reset --hard @{u}

没有一个解决方案工作,如果你只是改变了文件的许可(这是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 stash -u

是的,容易。

如果你真的很关心你的<unk>子,那么你可以跟随吉特<unk>子下降,但在那个时候你更好地使用(从Mariusz Nowak):

git checkout -- .
git clean -df

然而,我喜欢 git stash -u 最好的,因为它“排除”所有跟踪和未跟踪的变化在一个命令。 但是 git checkout -. 只排除跟踪的变化, git clean -df 只排除未跟踪的变化... 并输入两个命令是太多的工作:)

下面实际上只是一个解决方案,如果你正在与一个存储库的福克工作,在那里你经常同步(例如拖请求)与另一个复制。

我有一个类似的问题,也许不是相同的,我很遗憾地说我的解决方案不是理想的,但它最终是有效的。

我会经常有 git 状态消息如下(包含至少 2/4 文件):

$ git status
# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   doc/PROJECT/MEDIUM/ATS-constraint/constraint_s2var.dats
#       modified:   doc/PROJECT/MEDIUM/ATS-constraint/parsing/parsing_s2var.dats
#
# 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:   doc/PROJECT/MEDIUM/ATS-constraint/constraint_s2Var.dats
#       modified:   doc/PROJECT/MEDIUM/ATS-constraint/parsing/parsing_s2Var.dats

一个激动人心的眼睛会注意到,这些文件有双重的,这是一个单一的字母的情况下. 某种方式,我不知道什么导致我下这个路径开始(因为我没有工作这些文件自己从上流的repo),我已经转换了这些文件. 试试这个页面上列出的许多解决方案(和其他页面)似乎没有帮助。