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

On Linux/Unix, you can append files to the .gitignore file with the echo command. For example if you want to ignore all .svn folders, run this from the root of the project:

echo .svn/ >> .gitignore
查看更多
Animai°情兽
3楼-- · 2019-01-30 07:55

It's useful to define a complete .gitignore file for your project. The reward is safe use of the convenient --all or -a flag to commands like add and commit.

Also, consider defining a global ~/.gitignore file for commonly ignored patterns such as *~ , which covers temporary files created by Emacs.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-30 07:55

You have to install git-extras for this. You can install it in Ubuntu using apt-get,

$ sudo apt-get install git-extras

Then you can use the git ignore command.

$ git ignore file_name
查看更多
Lonely孤独者°
5楼-- · 2019-01-30 08:04

Using the answers already provided, you can roll your own git ignore command using an alias. Either add this to your ~/.gitconfig file:

ignore = !sh -c 'echo $1 >> .gitignore' -

Or run this command from the (*nix) shell of your choice:

git config --global alias.ignore '!sh -c "echo $1 >> .gitignore" -'

You can likewise create a git exclude command by replacing ignore with exclude and .gitignore with .git/info/exclude in the above.

(If you don't already understand the difference between these two files having read the answers here, see this question.)

查看更多
爷、活的狠高调
6楼-- · 2019-01-30 08:06

for names not present in the working copy or repo:

echo /globpattern >> .gitignore

or for an existing file (sh type command line):

echo /$(ls -1 file) >> .gitignore   # I use tab completion to select the file to be ignored  
git rm -r --cached file             # if already checked in, deletes it on next commit
查看更多
登录 后发表回答