how to write gitignore file to control sub-folder and files?

51 views
Skip to first unread message

Sand Glass

unread,
Oct 17, 2018, 10:29:53 AM10/17/18
to git-for-windows
I have a fpga project, it has many folders and files. I want to manage some of the files to git repo.
I try to use one .gitignore file to include some sub-folder files, but failed.

My folder file tree is something like this:
#############
my_fpga_pro/
    .git/
    .gitignore
    a.v
    b.v
    hdmi_rx/
        pakage_ip060/
            a.xci
        ip_b/
            b.xci
        design_hdmi.sdk/
            src/
                a.c
                b.c
                a.h
        design_hdmi.xpr
        hdmi_test.v
        hdmi_statistics.v
    rtl_folder_a/
        aa.v
        ab.v
#############

My .gitignore file is following:
###############
/*
!/hdmi_rx/

/hdmi_rx/*
!/hdmi_rx/pakage_ip060/
!/hdmi_rx/design_hdmi\.sdk/
##################

I save the .gitignore file and do following:
I expect include 'a.xci' and 'a.c, b.c, a.h', but not my expectation.
#################
[luoy@tteda basic_v3_git]$ git add -v .
add 'hdmi_rx/design_hdmi.xpr'
add 'hdmi_rx/hdmi_statistics.v'
add 'hdmi_rx/hdmi_test.v'
[luoy@tteda basic_v3_git]$ git status -s
A  hdmi_rx/design_hdmi.xpr
A  hdmi_rx/hdmi_statistics.v
A  hdmi_rx/hdmi_test.v
[luoy@tteda basic_v3_git]$ git --version
git version 2.16.4

Philip Oakley

unread,
Oct 17, 2018, 5:48:10 PM10/17/18
to Sand Glass, git-for-windows
Hi,

You possibly have the very first ignore wrong. The leading backslash
anchors the pattern.

There has been a recent discussion about the clarity of the
documenation, mainly about double asterisks but the same general issue
affects the understanding of backslash.

Perhaps try a single asterisk [*] to ignore everything then re-include
as required.

Alternatively you can place .gitignore files at many levels. You don't
have to put them all at the top level.

Philip
(comments made without checking the documentation...)
> --
> You received this message because you are subscribed to the Google
> Groups "git-for-windows" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to git-for-windo...@googlegroups.com
> <mailto:git-for-windo...@googlegroups.com>.
> To post to this group, send email to git-for...@googlegroups.com
> <mailto:git-for...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/git-for-windows/b4e02739-4a4e-4e72-803e-81d3a4d1e579%40googlegroups.com
> <https://groups.google.com/d/msgid/git-for-windows/b4e02739-4a4e-4e72-803e-81d3a4d1e579%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Sand Glass

unread,
Oct 17, 2018, 8:14:04 PM10/17/18
to git-for-windows
One folder level has a gitignore is ok. But if I do this, I cannot overview all the files whitch I have version controlled.
I expect one gitigonre file, that I can see the overview through gitigore file.
Or is there another way to overview my all files which are version controlled, if I use one gitignore every folder level?

Philip Oakley

unread,
Oct 18, 2018, 6:18:48 AM10/18/18
to git-for-windows
Have a look at `git check-ignore` to test which PATHS are ignored.

Then read the git ignore documentation three times and wonder....

Sand Glass

unread,
Oct 25, 2018, 4:26:32 AM10/25/18
to git-for-windows
git check-ignore -v the_specified_folder_name
if nothing print, it means the folder is include, otherwise it will tell you the folder is exclude in the specified ignore_files.
Reply all
Reply to author
Forward
0 new messages