简体   繁体   中英

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'. 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. 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! Below is a screenshot of my github remote repo. 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. Your remote repository will have the same structure the your working tree of your local repository. Nothing you can do about that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM