情况:我有一个Git存储库,其中包含已存在于索引中的文件.我对几个文件进行了更改,打开Git并使用"git add"将这些文件添加到我的临时区域.
问题:如何从暂存区域中删除其中一个文件但不将其从索引中删除或撤消对文件本身的更改?
有时,git建议git rm --cached取消暂存文件git reset HEAD file.我什么时候应该使用哪个?
编辑:
D:\code\gt2>git init
Initialized empty Git repository in D:/code/gt2/.git/
D:\code\gt2>touch a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a
nothing added to commit but untracked files present (use "git add" to track)
D:\code\gt2>git add a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Changes to …Run Code Online (Sandbox Code Playgroud) 我在我的本地仓库中对我的一些文件进行了更改,然后我做git add -A了我认为在暂存区域添加了太多文件的情况.如何从暂存区域删除所有文件?
在我这样做之后,我会手动做git add "filename".
是否有可能取消git中最后一个阶段(未提交)的更改?假设当前分支中有很多文件,有些是暂存的,有些则没有.在某些时候,一些愚蠢的程序员意外地执行了:
git add -- .
Run Code Online (Sandbox Code Playgroud)
...代替:
git checkout -- .
Run Code Online (Sandbox Code Playgroud)
这个程序员现在可以通过一些神奇的git命令取消他的最后一次更改吗?或者他应该在首先尝试之前做出承诺?
我已经看过所有类似的问题但是我已经仔细检查了一些奇怪的东西肯定会发生.
在一台服务器(Solaris with git 1.8.1)上,我克隆了git存储库,然后将.git文件夹复制到现有的实时文件中.这很完美,我可以跑
git status
Run Code Online (Sandbox Code Playgroud)
然后
git diff [filename]
Run Code Online (Sandbox Code Playgroud)
检查任何不同的文件.
在另一台服务器(Solaris with git 1.7.6)上,我做的完全一样
git diff [filename]
Run Code Online (Sandbox Code Playgroud)
即使文件的内容肯定不同,也不显示任何内容.我还测试了添加一个新文件,然后进行编辑.同样的问题,git status将文件显示为已更改但未git diff显示任何内容.如果我下载更改的文件并在本地运行diff,那么我得到diff输出.
当我想取消暂存文件时,我所有的 Git 教程都显示如下内容:
$ git add *
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: README.md -> README
modified: CONTRIBUTING.md
Run Code Online (Sandbox Code Playgroud)
此提示告诉我们git reset用于取消暂存文件。
但是,在我的终端中,我看到:
git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: cat.js -> catcat.js
renamed: tolendo.gogo -> tolendo.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme (copy).md
tolendo (copy).txt
zing (copy).html
Run Code Online (Sandbox Code Playgroud)
我的终端告诉我使用,git …
我犯了一个错误并打电话git add -all,现在添加了所有文件.我没有做commit和push.如何撤消我的动作?
我在Mac 10.6.6上使用Git 1.7.4.1.从命令行,如何仅在单个目录中提交更改?我通过这样做添加了目录:
git add my-dir
Run Code Online (Sandbox Code Playgroud)
但是做
git commit -a
Run Code Online (Sandbox Code Playgroud)
显示我的仓库中所有更改的列表,我只想提交并推送更改my-dir.
可能重复:
在提交之前撤消git add
当我在处理我的项目时,我意外地使用以下命令添加了文件
git add file
Run Code Online (Sandbox Code Playgroud)
我还没跑
git commit.
Run Code Online (Sandbox Code Playgroud)
如何从提交中撤消或删除这些新添加的文件?
请帮忙.