4

I have a Git repository that contains a Libs directory in the root. This directory contains all the compiled .lib files that I want to include in the repository and push to main repo. The structure of Libs directory is:

Libs
...--| x64
........--| Release
........--| Debug

The problem is that I am unable to make Git include LIB files inside Release and Debug folders. I think its because Release and Debug folders are excluded by gitignore:

# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

What I tried:

!/Libs/*/*.lib
!/Libs/x64/Release/*
A9S6
  • 6,575
  • 10
  • 50
  • 82
  • May I ask why you want to push build results into the main repository even though someone already explicitly excluded them? – David Ongaro May 23 '14 at 07:46
  • I have third party libs in these directories that I have compiled separately. I do not want to include the source code of these third-party components in my project so I am only keeping the compiled versions. People checking-out my project won't have to go through the pain of compiling all the third-party stuff as these components are not downloadable in binary form. – A9S6 May 23 '14 at 08:20
  • I don't think adding files under x64 is the right thing to do. X64 folder should really be seen as a dump. Instead, I would advise to create a project in your solution dedicated to *copy* the prebuilt downloaded libs into x64/Release and x64/Debug. Typically that would be a project without a Source or Headers group, just a folder containing your prebuilt stuff and a Post-Build Event using a xcopy /y command. And you can use $(SolutionDir)/$(Platform)/$(Configuration) as a target dir. – Mic Aug 08 '17 at 05:27

1 Answers1

10

You would need to use:

git add --force Libs

In order to add them in spite of the .gitignore.

You can check at any time which .gitignore and which rules of the .gitignore is preventing you to consider a particular folder with:

git check-ignore -v /path/to/an/element

For modifying your .gitignore to not ignore a particular sub-folder, consider ".gitignore exclude folder but include specific sub-folder", especially:

If you exclude folder/, then everything under it will always be excluded (even if some later negative exclusion pattern (“unignore”) might match something under folder/). (*)
(*: unless certain conditions are met in git 2.?, see below)

For instance, in your case try (git 1.8.2+):

Libs/**/*
!Libs/x64/Release/

Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

That means, with git 2.9+, this could have worked:

/Libs
!/Libs/x64/Release
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • "git add --force Libs" worked. Thanks. Is there also a "git ignore --force xxxx"? There is a abc_i.h that never gets ignored even though its in gitignore file. – A9S6 May 23 '14 at 06:49
  • @A9S6 `abc_i.h` could never be ignored... if it is already tracked (added and committed) by Git. – VonC May 23 '14 at 09:17
  • This is auto-generated, not committed by Git. Is it possible to somehow know if this is tracked internally (by mistake maybe)? Can I "untrack" it? – A9S6 May 23 '14 at 11:56
  • 1
    @A9S6 to untrack, `git reset -- path/to/abc_i.h` – VonC May 23 '14 at 11:58
  • Sorry, yes it was being tracked by Git. I'll remove it. Thanks again. – A9S6 May 23 '14 at 12:01