Is there an ignore command for git like there is f

2019-01-30 07:01发布

I am a new user to git and I am starting a new project. I have a bunch of dot files that I would like to ignore. Is there an ignore command for git like there is for svn?

11条回答
成全新的幸福
2楼-- · 2019-01-30 07:39

There is no special git ignore command.

Edit a .gitignore file located in the appropriate place within the working copy. You should then add this .gitignore and commit it. Everyone who clones that repo will than have those files ignored.

Note that only file names starting with / will be relative to the directory .gitignore resides in. Everything else will match files in whatever subdirectory.

You can also edit .git/info/exclude to ignore specific files just in that one working copy. The .git/info/exclude file will not be committed, and will thus only apply locally in this one working copy.

You can also set up a global file with patterns to ignore with git config --global core.excludesfile. This will locally apply to all git working copies on the same user's account.

Run git help gitignore and read the text for the details.

查看更多
The star\"
3楼-- · 2019-01-30 07:40

Create a file named .gitignore on the root of your repository. In this file you put the relative path to each file you wish to ignore in a single line. You can use the * wildcard.

查看更多
女痞
4楼-- · 2019-01-30 07:43

A very useful git ignore command comes with the awesome tj/git-extras.

Here are a few usage examples:

List all currently ignored patterns

git ignore

Add a pattern

git ignore "*.log"

Add one of the templates from gitignore.io

git ignore-io -a rails

git-extras provides many more useful commands. Definitely worth trying out.

查看更多
做个烂人
5楼-- · 2019-01-30 07:49

I hope it's not too late.

If you are on Windows you can just do the following to create a .gitignore file

echo name_of_the_file_you_want_to_ignore.extension > .gitignore

In order to edit .gitignore you can run

notepad .gitignore
查看更多
放荡不羁爱自由
6楼-- · 2019-01-30 07:51

You could also use Joe Blau's gitignore.io

Either through the web interfase https://www.gitignore.io/

Or by installing the CLI tool, it's very easy an fast, just type the following on your terminal:

Linux:
echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bashrc && source ~/.bashrc

OSX:
echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bash_profile && source ~/.bash_profile

And then you can just type gi followd by the all the platform/environment elements you need gitignore criteria for.

Example!
Lets say you're working on a node project that includes grunt and you're using webstorm on linux, then you may want to type:
gi linux,webstorm,node,grunt > .gitignore ( to make a brand new file)
or
gi linux,webstorm,node,grunt >> .gitignore ( to append/add the new rules to an existing file)

bam, you're good to go

查看更多
可以哭但决不认输i
7楼-- · 2019-01-30 07:53

You have two ways of ignoring files:

  • .gitignore in any folder will ignore the files as specified in the file for that folder. Using wildcards is possible.
  • .git/info/exclude holds the global ignore pattern, similar to the global-ignores in subversions configuration file.
查看更多
登录 后发表回答