I created a git repository folder which contains all of my C++ code. When I compile the code with g++ -g filename.cpp -o filename -lgraph
in my Ubuntu 18.04, it creates a filename
file without extension. I want git to stop tracking all these created files while I do git add .
and track the rest. What should I add to the .gitignore file so that these files are ignored?
Asked
Active
Viewed 1,191 times
0

deekeh
- 675
- 1
- 6
- 21
-
1`filename`? Or why not put the output not into the repository or give all output a name, so you can ignore it: `filename.tmpout` then add `*.tmpout` – RoQuOTriX Jan 22 '20 at 12:38
-
@RoQuOTriX So, should I add an extension *.tmpout* to the output files? Will the output file still run the same? – deekeh Jan 22 '20 at 12:46
-
@deekeh Why can't you just add `filename` to .gitignore? – user253751 Jan 22 '20 at 12:48
-
https://stackoverflow.com/search?q=%5Bgitignore%5D+without+dots – phd Jan 22 '20 at 12:48
-
@user253751 All files will have different names. I just used ```filename``` as a placeholder to the file name. I want want git to ignore all the output files at once. – deekeh Jan 22 '20 at 12:50
1 Answers
1
I would suggest to use an build Folder outside the source Folder.
But if you really need the output executable to be in the source Folder you can add following to .gitignore
:
*
!*.cpp
!*.h
If you do so, git ignores all files which are not cpp
or c
-Files
*
git ignores all files*.cpp
but does not ignore cpp files*.h
but does not ignore h files
Depending on other files you have in your source Folder you have to exclude them too.
But it is better to have an dedicated build folder.
Edit: You can even have the build folder inside your source folder and exclude everything inside this folder.
build/*
Make sure the build
folder exists
mkdir build
and modify your call to g++
g++ -g filename.cpp -o build/filename -lgraph

dnlkng
- 829
- 1
- 10
- 16