English 中文(简体)
新的git存储库和已经重置的git不起作用
原标题:new git repository and already git reset does not work
  • 时间:2010-10-08 22:43:33
  •  标签:
  • git

1) 我在一个文件夹中执行了git-init

2) 添加了一些项目文件

3) 我做了git-add*,所以它递归地添加了所有文件

4) 我意识到我添加了一堆不想被版本化的文件,所以我想撤消添加

5) git-reset会给我以下错误:

fatal: Failed to resolve  HEAD  as a valid ref.

6) <code>git status</code>仍然显示所有添加的文件

7) 我尝试<code>git reset-hard HEAD</code>,结果出现以下错误:

fatal: ambiguous argument  HEAD : unknown revision or path not in the working tree.
Use  --  to separate paths from revisions

8) <code>git status</code>仍然显示所有添加的文件

此时我该怎么办?

最佳回答
git rm [-r] --cache -- <file>…

would be the right command to remove from the index the file you don t want to commit.
Any reset command won t work, since you have to any commit yet in your newly created repository.

git-rm手册页

--cached

Use this option to unstage and remove paths only from the index.
Working tree files, whether modified or not, will be left alone.

-r

在给定前导目录名时允许递归删除。

<file>…

Files to remove.
Fileglobs (e.g. *.c) can be given to remove all matching files. If you want git to expand file glob characters, you may need to shell-escape them.
A leading directory name (e.g. dir to remove dir/file1 and dir/file2) can be given to remove all files in the directory, and recursively all sub-directories, but this requires the -r option to be explicitly given.

问题回答

如果您想撤消对git的初始提交,请在项目目录文件夹中运行以下命令:

$ rm -rf ./.git

这将删除您的本地git存储库,以便您可以使用git-init命令重新开始。





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签