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:44

Also in your \.git\info projects directory there is an exclude file that is effectively the same thing as .gitignore (I think). You can add files and directories to ignore in that.

查看更多
像晚风撩人
3楼-- · 2019-01-01 14:45

I had some issues creating a file in windows explorer with a . at the beginning.

a workaround was to go into the commandshell and create a new file using "edit"

查看更多
还给你的自由
4楼-- · 2019-01-01 14:45

To ignore an entire directory in git, the easiest way is to include a .gitignore file within the target directory which simply contains "*"

An illustrative example,

Example System

/root/
    .gitignore
    /dirA/
        someFile1.txt
        someFile2.txt
    /dirB/
        .gitignore
        someFile3.txt
        someFile4.txt

Goal

  • ignore the contents of /dirB/

Top Level .gitignore (/root/.gitignore)

  • This is where your standard gitignore info goes

Ignored Directory .gitignore (/root/dirB.gitignore)

  • This file just reads as '*' and the directory is ignored completely, itself and all files!

and it's that simple :)

查看更多
只靠听说
5楼-- · 2019-01-01 14:47

I've had some problems getting git to pickup the .gitignore file on Windows. The $GIT_DIR/info/exclude file always seems to work though. The downside of this approach, however, is that the files in the $GIT_DIR directory are not included in the check-in, and therefore not shared.

( p.s. $GIT_DIR is usually the hidden folder named .git )

查看更多
心情的温度
6楼-- · 2019-01-01 14:49

On windows and Mac, if you want to ignore a folder named Flower_Data_Folder in the current directory, you can do:

echo Flower_Data_Folder >> .gitignore

If its a file named data.txt

echo data.txt >> .gitignore

if its a path like "Data/passwords.txt"

echo "Data/passwords.txt" >> .gitignore.

查看更多
登录 后发表回答