简体   繁体   English

Git-列出根目录中的每个文件后,“没有添加任何内容来提交但存在未跟踪的文件”

[英]Git - “nothing added to commit but untracked files present” after listing every file in root

I am attempting to commit some files to Github, to a GitHub Pages branch. 我正在尝试将某些文件提交给Github和GitHub Pages分支。 In response, it stated "Nothing added to commit but untracked files present" after listing out every folder in my root directory . 作为回应,它列出了我根目录中的每个文件夹后,显示“没有添加任何内容,但存在未跟踪的文件”。 My project is inside of a folder inside of my Documents folder. 我的项目在我的Documents文件夹内的一个文件夹内。 Does anyone understand why this might be happening? 有谁知道为什么会这样?

    On branch gh-pages
Untracked files:
    ../../.atom/
    ../../.bash_history
    ../../.gimp-2.8/
    ../../.gitconfig
    ../../.gradle/
    ../../.idlerc/
    ../../.jssc/
    ../../.mongorc.js
    ../../.node_repl_history
    ../../.oracle_jre_usage/
    ../../.ssh/
    ../../.thumbnails/
    ../../.vim/
    ../../.viminfo
    ../../AppData/
    ../../Contacts/
    ../../Desktop/
    ../Thumbs.db
    ../desktop.ini
    ../forge.aup
    ../hp.system.package.metadata/
    ../../Downloads/
    ../../Dropbox/
    ../../Favorites/
    ../../Helper/
    ../../IntelGraphicsProfiles/
    ../../Links/
    ../../MongoDB/
    ../../Music/
    ../../OneDrive/
    ../../Pictures/
    ../../Saved Games/
    ../../Searches/
    ../../Videos/
    nothing added to commit but untracked files present

It seems most people are missing the crux of the issue here, so I'll add a bit: 似乎大多数人在这里都没有找到问题的症结所在,所以我要补充一点:

You want to know why it's listing things outside your project directory as untracked. 您想知道为什么它会将项目目录外的内容列出为未跟踪。 As axiac observed, this most likely means that the .git folder is in the wrong place. 正如axiac所观察到的,这很可能意味着.git文件夹在错误的位置。 The .git folder contains all the metadata and repo-specific configuration, as well as the state of the index and the database (which in turn contains the version history, etc.) .git文件夹包含所有元数据和特定于存储库的配置,以及索引和数据库的状态(依次包含版本历史记录等)。

When you're in a given working directory and you run a git command (if it's one that expects you to be in a repo... which is most of them), it looks for a .git folder in that directory; 当您在给定的工作目录中并运行git命令(如果它是一个希望您位于存储库中的命令...多数情况下)时,它将在该目录中查找.git文件夹; then if it doesn't find one it checks the parent directory, and so on until it either finds one or reaches the filesystem root. 然后,如果找不到该目录,则检查父目录,依此类推,直到找到一个目录或到达文件系统根目录为止。 If it doesn't find one it gives an error, but if it does find one, then it takes that to be the root of the default work tree for the repository. 如果找不到一个,则会报错,但是如果找到一个,则会将其作为存储库默认工作树的根。 (There are some cases where this description isn't applicable, but it should apply to your situation.) (在某些情况下,此描述不适用,但应适用于您的情况。)

So probably .git/ is in the wrong place. 因此, .git/可能在错误的位置。 But that raises another question: Why doesn't git think that you've deleted everything it already knew about? 但这又引发了一个问题:为什么git不认为您已经删除了它已经知道的所有内容?

Of course if this is a new repo that you're just creating, that would explain it; 当然,如果这是您刚刚创建的新存储库,那就可以解释了。 but if it's anything else, git should be listing deletion of any files from the previous commit as also being untracked changes. 但是如果还有其他事情,git应该列出从先前提交中删除的所有文件,以及未跟踪的更改。 (At least, it should if you do a git status . (至少,如果执行git status ,应该会。

So what to do next: 那么下一步该怎么做:

If you're creating a new repo, it may be best to delete .git/ from your filesystem root, cd to your project directory and rerun git init 如果要创建新的仓库,最好从文件系统根目录中删除.git/ ,将其cd到项目目录中,然后重新运行git init

If this is an existing repo, try running git status to confirm that it sees untracked deletions of everything along with all your top-level files/folders as untracked files. 如果这是现有的存储库,请尝试运行git status以确认它将所有未删除的内容以及所有顶级文件/文件夹都视为未跟踪的文件。 If so, you surely need to move the .git/ that's in your filesystem root to the project directory. 如果是这样,您肯定需要将文件系统根目录中的.git/移动到项目目录。

Then you should be able to stage and commit your changes as usual. 然后,您应该能够照常上演并提交更改。

The "nothing added to commit" message refers to empty directories that have been added. “未添加任何内容提交”消息是指已添加的空目录。 GIT manages versions of files, not directories. GIT管理文件的版本,而不是目录。 When you git add a file in one of those directories, you will see them listed as "new file: ...". 当您在其中一个目录中git添加文件时,您会看到它们被列为“新文件:...”。 The "untracked files present" refers to "../Thumbs.db", for which git add has not yet been run. “存在的未跟踪文件”是指尚未运行git add的“ ../Thumbs.db”。 Files are not "tracked" by GIT unless they have been "add"-ed to the index that GIT maintains. 除非文件已“添加”到GIT维护的索引中,否则文件不会被GIT“跟踪”。

If you want to commit all the files, try the below commands 如果要提交所有文件,请尝试以下命令

git add ../../.

git commit -m "commit message"

As per your question, you might be in two level sub directory of the repo path and executing git commands 根据您的问题,您可能在回购路径的两个子目录中并执行git命令

It's good to initialise the project repository, so remove .git folder from root directory and change the directory to project path and initialise git repo by git init , Thanks @MarkAdelsberger 初始化项目存储库是很好的,因此从根目录中删除.git文件夹,并将目录更改为项目路径,然后通过git init初始化git repo,谢谢@MarkAdelsberger

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Git:没有添加任何提交但存在未跟踪的文件 - Git:nothing added to commit but untracked files present Git 没有向提交添加任何内容,但存在未跟踪的文件 - 即使将这些文件添加到 gitignore - Git nothing added to commit but untracked files present - even with those files added to gitignore npm-debug.log位于.gitignore文件中,但我仍然收到消息“没有添加任何内容来提交但存在未跟踪的文件(使用” git add”进行跟踪)” - npm-debug.log is in .gitignore file, but I still get the messsage “nothing added to commit but untracked files present (use ”git add“ to track)” Git commit -a “未跟踪的文件”? - Git commit -a “untracked files”? git commit显示未跟踪的文件 - git commit shows untracked files GIT:恢复到之前的提交后恢复未跟踪的文件 - GIT: Restoring untracked files after reverting to previous commit Git:如何获取所有未跟踪文件的列表,忽略未跟踪的子模块? - Git: How to get a listing of all untracked files, ignoring untracked submodules? Git:在根级别“什么也没提交”,但是未修改的文件在子文件夹中显示为已修改 - Git: “nothing to commit” at root level, but unmodified files shown as modified in subfolder git checkout HEAD〜2(示例)将删除未跟踪的文件(如果它们是在上次提交时添加的) - git checkout HEAD~2 (example) deletes untracked files if they were added with last commit Git:提交修改/未跟踪文件的子集 - Git: Commit a subset of modified/untracked files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM