MacOS:从git历史记录中清除所有未跟踪文件

siv3szwd  于 2022-11-20  发布在  Git
关注(0)|答案(1)|浏览(203)

很久以前,我在一个项目中使用了git,我开始了一个项目,然后离开了。现在我开始了一个新的项目,我想使用git进行版本控制。
当我检查git是否可用或以前是否已卸载时,我可以看到它是可用的:

% git --version
git version 2.31.1

% which git
/usr/local/bin/git

但后来,它似乎git是跟踪一些文件,我不再需要,并会清除一切完全。

~ % git status
warning: could not open directory '.Trash/': Operation not permitted
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    .CFUserTextEncoding
    .DS_Store
    .RapidMiner/
    .Rhistory
    .Xauthority
    .anaconda/
    .android/
    .anydesk/
    .atom/
    .bash_history
    .bash_profile
    .bash_profile-anaconda3.bak
    .bash_profile.backup
    .bash_profile.pysave
    .bash_sessions/
    .....

这些是我不再需要跟踪的文件(甚至不记得它们属于哪个项目)。
所以我想清除这个历史记录,为我将要开始工作的新项目创建一个干净的git
所以我已经完成了以下所有命令:

git git reset --hard
git clean -f
git clean -fx

然而,我仍然认为这是未跟踪的:

~ % git status
warning: could not open directory '.Trash/': Operation not permitted
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    .CFUserTextEncoding
    .DS_Store
    .RapidMiner/
    .Rhistory
    .Xauthority
    .anaconda/
    .android/
    .anydesk/
    .atom/
    .bash_history
    .bash_profile
    .bash_profile-anaconda3.bak
    .bash_profile.backup
    .bash_profile.pysave
    .bash_sessions/
    .....

我如何摆脱这些,开始一个干净的git版本?

mkh04yzy

mkh04yzy1#

首先,那些被列为“untracked”的文件,就像它听起来的那样,* 不 * 被Git跟踪。它们被列出是因为它们在Git repo文件夹中,并且当前没有被忽略。这个问题很快就会消失的。
看起来你在你的主目录中创建了一个Git仓库(~)。该目录中可能有一个.git文件夹。如果您不再需要它,可以将其删除。(为了以防万一,可以考虑先备份它。)然后考虑创建一个新的文件夹,用来存储所有的Git repos。可能是一个名为GitCodeRepos等的文件夹。然后在该文件夹中,为您要处理的每个项目创建一个文件夹,例如Project1。然后导航到该文件夹并键入:

git init

在该文件夹中初始化一个新的Git存储库。你可以(通常应该)为你正在处理的每个独立项目创建单独的Git存储库。

相关问题