简体   繁体   English

如何在git中添加和跟踪文件而不跟踪它们所在的目录?

[英]How can I add and track files in git without tracking the directories they are in?

未跟踪的文件

As you can see from the picture, I have some files nested in some directories. 从图片中可以看到,我在某些目录中嵌套了一些文件。 For example in the '../../roadTrip/' directory I have a file called 'main.cpp'. 例如,在“ ../../roadTrip/”目录中,我有一个名为“ main.cpp”的文件。 I want to track ONLY this file and not the directories it is in, because that is the only file I want to push to my remote repo. 我只想跟踪此文件,而不是它所在的目录,因为这是我要推送到远程仓库的唯一文件。 I tried ignoring the directories the file was in, in the .gitignore file by using wildcards, but it ignores the file also. 我尝试使用通配符忽略.gitignore文件中文件所在的目录,但它也忽略该文件。 Is there any way I can achieve this effect without having to literally take out the file from the nested directories and then push it? 有什么方法可以实现这种效果,而不必从嵌套目录中实际删除文件然后将其推送?


--UPDATE! --update! Below is a screenshot of my github remote repo. 下面是我的github远程仓库的屏幕截图。 It shows the whole directory, and when I open it, the file is inside. 它显示了整个目录,当我打开它时,文件就在里面。 This means the file was successfully pushed, but I don't want that. 这意味着文件已成功推送,但我不希望这样。 I want the file to be pushed alone without the directories it is in. 我希望文件被单独推送而没有目录。 文件上传

Something along the lines of this: 与此类似:


源文件

You write 你写

I want the file to be pushed alone without the directories it is in. 我希望文件被单独推送而没有目录。

That is not possible with Git. 这是不可能的使用Git。 Your remote repository will have the same structure the your working tree of your local repository. 您的远程存储库将具有与本地存储库的工作树相同的结构。 Nothing you can do about that. 您无能为力。

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

相关问题 如何使用 Git 跟踪目录而不是它们的文件? - How to track directories but not their files with Git? 如何使用 Git LFS 跟踪存储库的任何子目录中的任何(任意)文件 - 但不跟踪其根目录中的任何文件? - How do I use Git LFS to track any (arbitrary) file in any subdirectory of a repository - but without tracking any files in its root? 如何在 git rm 命令后将文件夹和文件添加回 git 跟踪? - How can I add folders and files back to git tracking after git rm command? 如何在 git 中保留 png 文件而不跟踪它们? - How do I keep png files in git without tracking them? 如何告诉git仅跟踪与软件相关的目录,而不跟踪用户生成的内容? - How can I tell git to track only software-related directories, and not user-generated content? Git目录-如何跟踪目录但不跟踪内容 - Git directories - how to track directories but not content git-开始跟踪未跟踪的远程文件/目录 - git - start tracking untracked remote files/directories 为什么我不能用git跟踪这些文件? - Why can't I track these files with git? 如何使用git add或git lfs跟踪大量文件 - How to use git add or git lfs track A LOT of files 如何指示git停止跟踪外部目录? - how to instruct git to stop tracking outside directories?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM