1

I want to ignore any files excepts *.c files from the git system. I wrote .gitignore file like this.

!**/*.c

Though my files is not ignored.

~/p/normal_linux_programming (master) $ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified:   .gitignore
new file:   bell/a.out
new file:   bell/bell.c
new file:   bell/bell.c~
new file:   cat/#cat.c#
new file:   cat/a.out
new file:   cat/cat
new file:   cat/cat.c~
new file:   cat/cat2
new file:   cat/cat2.c~
new file:   cat/data
new file:   cat/data~
new file:   chmod/chmod
new file:   chmod/chmod.c
new file:   chmod/chmod.c~
new file:   chmod/unko
new file:   grep/a.out
new file:   grep/grep
new file:   grep/grep.c~
new file:   head/#head.c#
new file:   head/.#head.c
new file:   head/head
new file:   head/head.c~
new file:   hello/hello
new file:   hello/hello.c
new file:   hello/hello.c~
new file:   ln/ln
new file:   ln/ln.c
new file:   ln/ln.c~
new file:   ls/ls
new file:   ls/ls.c
new file:   ls/ls.c~
new file:   mkdir/mkdir
new file:   mkdir/mkdir.c
new file:   mkdir/mkdir.c~
new file:   mv/#mv.c#
new file:   mv/.#mv.c
new file:   mv/NOTJUNK
new file:   mv/mv
new file:   mv/mv.c
new file:   rm/rm
new file:   rm/rm.c
new file:   rmdir/rmdir
new file:   rmdir/rmdir.c
new file:   rmdir/rmdir.c~
new file:   stat/stat
new file:   stat/stat.c
new file:   stat/stat.c~
new file:   symlink/symlink
new file:   symlink/symlink.c
new file:   symlink/symlink.c~
new file:   tail/#tail.c#
new file:   tail/.#tail.c
new file:   tail/tail
new file:   tail/tail.c~
new file:   wcl/a.out
new file:   wcl/wcl
new file:   wcl/wcl.c~

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:   .gitignore

How can I do that?
I want to only archive *.c source files.

1 Answers1

0

I want to ignore any files excepts *.c

Write it on 2 separate lines

# ignore all files 
*

# do not ignore any .c files
!*.c

# you also don't want to ignore your .gitignore file so you have to add it as well
!*.gitignore
CodeWizard
  • 128,036
  • 21
  • 144
  • 167