在为当前项目进行git提交之前,如何解决未跟踪文件的历史记录列表?

问题描述

我想向一个{master}项目中添加2个文本文件,但是我不断获得与当前项目无关的未跟踪文件列表。为什么会发生这种情况,我该如何解决? MacOS v10.15.7 Catalina终端

添加了第一个文本文件:

git add file1.txt

添加了第二个文本文件:

git add file2.txt

查看工作目录和暂存文件:

git status

要提交的更改:

new file: file1.txt

new file: file2.txt

加上不断获取未跟踪文件的列表:

    .Trash/
    .anaconda/
    .config/
    .idlerc/
    .ipython/
    .local/
    .matplotlib/
    .npm/
    .spyder-py3/
    .vscode/
    Applications/
    Creative Cloud Files/
    Desktop/
    Documents/
    Downloads/
    Library/
    Moon/
    Movies/
    Music/
    Pictures/
    Public/
    helloworld/
    opt/

我删除了pronto!

rm -rf ~/.git

已选中

git status

输出

fatal: not a git repository (or any of the parent directories): .git

我将重新开始我的项目,更加了解!

解决方法

似乎您在主目录中初始化了git。您可能想在正在创建的软件的项目目录中对其进行初始化。每个项目都应该有自己的git repo。您可以将git repo从主文件夹中删除,方法是将其移动到另一个目录或使用rm -Rf ~/.git完全删除它(注意:这是不可撤消的!)完成后,将cd放入您想要的文件夹/项目中跟踪并执行另一个git init

cd <some project folder>
git init
git add file1.txt

如果您打算将整个主目录放入git(我不建议这样做),则必须将所有不想跟踪的目录和文件都放入.gitignore文件中或仅使用git add file1.txt手动添加两个文件。 Git会跟踪其目录中的所有文件,除非将它们明确地放入gitignore中。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...