Ignoring directories in Git repos on Windows

2019-01-01 14:19发布

How can I ignore directories or folders in Git using msysgit on Windows?

17条回答
时光乱了年华
2楼-- · 2019-01-01 14:24

Just in case you need to exclude sub folders you can use the ** wildcard to exclude any level of sub directory.

**/build/output/Debug/
查看更多
大哥的爱人
3楼-- · 2019-01-01 14:31

In Windows there's an extra catch with slashes. Excluding a single directory in .gitignore with

dir_to_exclude/

will possibly work, but excluding all directories with

/

causes problems when you have file names with spaces (like my file.txt) in your directory: Git bash escapes these spaces with a backslash (like my\ file.txt) and Git for Windows doesn't distinguish between / and \.

To exclude all directories better use:

**/

Two consecutive asteriscs signify directory contents.

查看更多
ら面具成の殇う
4楼-- · 2019-01-01 14:31

You can create the ".gitignore" file with the contents:

*
!.gitignore

It works for me and simples.

查看更多
旧时光的记忆
5楼-- · 2019-01-01 14:35

If you want to maintain a folder and not the files inside it, just put a ".gitignore" file in the folder with "*" as content. This file will ignore all content from repository. But .gitignore will be include in your repo.

$ git add path/to/folder/.gitignore

If you add empty folder, you receive this message (.gitignore is hidden file)

The following paths are ignored by one of your .gitignore files:
path/to/folder/.gitignore
Use -f if you really want to add them.
fatal: no files added

So, use "-f" to force add:

$ git add path/to/folder/.gitignore -f
查看更多
泛滥B
6楼-- · 2019-01-01 14:36

I had similar issues, I work on a windows tool chain with a shared repo with linux guys, they happlily create files with the same [except for case] names in a given folder.

The effect is that I can clone the repo and immediatly have dozens of 'modified' files that if I checked in would create havoc.

I have windows set to case sensitive and git to not ignore case but it still fails (in the win32 api calls apparently).

If I gitignore the files then I have to remember to not track the .gitignore file.

But I found a good answer here http://archive.robwilkerson.org/2010/03/02/git-tip-ignore-changes-to-tracked-files/index.html

Chris

查看更多
几人难应
7楼-- · 2019-01-01 14:38

When everything else fails try editing the file

/.git/info/exclude

and adding the directories you want to the end of the file, like this:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
assets/
compiled/

I added the folders "assets" and "compiled" to the list of files and directories to ignore.

查看更多
登录 后发表回答