简体   繁体   中英

How to finally ignore a file in all sub-directories via .gitignore

I know there are lots of duplicate questions but I'm fully confused. I should admit I'm completely new to Git. I'm using RabbitVCS, However, I edit the .gitignore file using gedit manually. That's what I have done:

  1. I have created a repository in Github.
  2. I cloned it in my local computer using RabbitVCS.
  3. I have pasted all files and folders of project into the repository.
  4. I have created a .gitignore file in the root of repository which includes this pattern: *~ .

I haven't commited anything yet .

I want to ignore all ~ and such other temp files in root and sub-directories. It ignores all files in root, but has no effect in sub-directories. When I want to commit using RabbitVCS, I can see them in the commit window.

I'm confusing because in Bazaar, we first add files, then commit them. But it Git, it seems we should just commit to add new files! Is it right?

What am I doing wrong? should I commit first?

From the gitignore manual :

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

As Jan Hudec writes, you can just use *~ :

$ mkdir test
$ cd test
$ git init
Initialized empty Git repository in /tmp/test/.git/
$ echo '*~' > .gitignore
$ mkdir -p some/deep/directory
$ touch some/deep/directory/test.txt
$ touch some/deep/directory/test.txt~
$ git add some/deep/directory/test.txt*
The following paths are ignored by one of your .gitignore files:
some/deep/directory/test.txt~
Use -f if you really want to add them.
fatal: no files added

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