1

Here is my .gitignore file:

# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*
!/log/.keep
/tmp

# Ignore application configuration
/config/application.yml
/config/application.yml.bak
*.bak

Now, my repository is at https://github.com/rmohan80/learn-rails

Why would my latest commit -- "add configuration for email" add Readme.rdoc.bak but ignore .gitignore.bak

Any clues?

2 Answers 2

1

The star character does do match files beginning with a period. You can add .*.bak to ignore them in your case or you can change the glob option in your shell :

# capture dot file
shopt -s dotglob

# do git stuff here

# stop capturing dot file
shopt -u dotglob

A similar problem solved here : https://stackoverflow.com/a/19365350

3
  • I've updated the question to make it more clear. However, the problem isn't with the shell intrepretation - a ls *.bak shows all the files with .bak correctly - i.e. 4 files - including .gitignore.bak and Readme.rdoc.bak
    – zooter
    Dec 12, 2015 at 11:56
  • @zooter, git uses slightly different rules. For example the leading / does not mean you are excluding a file somewhere in the root-path of your filesystem. Just give Slagt's first suggestion a try. Modify one of the newly excluded files and run a "git status" to see that nothing gets reported as modified.
    – benjamin
    Dec 12, 2015 at 12:51
  • Not seem to be working - I added .*.bak and output C:\Users\ram\ruby\learn-rails [master +3 ~2 -0 !]> git status On branch master Your branch is up-to-date with 'origin/master'. 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 modified: README.md.bak Untracked files: (use "git add <file>..." to include in what will be committed) README.md.bak.bak config/environments/development.rb.bak config/secrets.yml.bak
    – zooter
    Dec 12, 2015 at 12:58
1

You have to checkout the HEAD, so that your repository looks unmodified. Then run the following:

$ echo '*.*.bak' >> .gitignore

To exclude files that are formatted like README.md.bak.

And run

$ echo '**/*.bak' >> .gitignore

to exclude files that are formatted like README.bak anywhere in the tree below the current directory.

Having .bak.bak files is something you don't want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.