Force add despite the .gitignore file

2019-01-08 03:34发布

Is there a way to force git to add a file despite the .gitignore file?

标签: git gitignore
3条回答
\"骚年 ilove
2楼-- · 2019-01-08 03:53

See man git-add:

   -f, --force
       Allow adding otherwise ignored files.

So run this

git add --force my/ignore/file.foo
查看更多
3楼-- · 2019-01-08 03:53

Despite Daniel Böhmer's working solution, Ohad Schneider offered a better solution in a comment:

If the file is usually ignored, and you force adding it - it can be accidentally ignored again in the future (like when the file is deleted, then a commit is made and the file is re-created.

You should just un-ignore it in the .gitignore file like that: Unignore subdirectories of ignored directories in Git

查看更多
走好不送
4楼-- · 2019-01-08 04:02

Another way of achieving it would be to temporary edit the gitignore file, add the file and then revert back the gitignore. A bit hacky i feel

查看更多
登录 后发表回答