gitignore

What is .gitignore exactly?

ぃ、小莉子 提交于 2019-11-26 21:16:07
I just created a Github repository and was wondering what the .gitignore file was for. I started by not creating one, but added one due to the fact that most repositories have one. Do I need to have one? Can/do I just ignore it, or does it have a use? I did some research on the subject but couldn't find a concrete explanation. .gitignore tells git which files (or patterns) it should ignore. It's usually used to avoid committing transient files from your working directory that aren't useful to other collaborators, such as compilation products, temporary files IDEs create, etc. You can find the

How to remove files that are listed in the .gitignore but still on the repository?

徘徊边缘 提交于 2019-11-26 21:12:53
I have some files in my repository that should be ignored, i added them to the .gitignore but, of course, they are not removed from my repository. So my question is, is there a magic command or script using filter-branch that can rewrite my history and remove all these files easily? Or simply a command that will create a commit that will remove them ? You can remove them from the repository manually: git rm --cached file1 file2 dir/file3 Or, if you have a lot of files: git rm --cached `git ls-files -i --exclude-from=.gitignore` But this doesn't seem to work in Git Bash on Windows. It produces

Can I include other .gitignore file in a .gitignore file? (like #include in c-like languages)

て烟熏妆下的殇ゞ 提交于 2019-11-26 20:12:50
问题 I have some files like vim.gitignore , SVN.gitignore and CVS.gitignore (spread around on my hard disk). Can I simply include these gitignore files in a .gitignore file in a new Git project? Edit : I have a global ignore file already. I just want to ignore different files in different types of projects, is this possible? 回答1: You could: Have a template repo with: those xxx.gitignore files in it: a .gitignore file with " xxx-gitignore-xxx " in it (in other word, with a content you can easily

How to exclude file only from root folder in Git

时间秒杀一切 提交于 2019-11-26 19:31:32
I am aware of using .gitignore file to exclude some files being added, but I have several config.php files in source tree and I need to exclude only one, located in the root while other keep under revision control. What I should write into .gitignore to make this happen? From the documentation : If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file). A leading slash matches the beginning of the pathname.

Using .gitignore to ignore everything but specific directories

吃可爱长大的小学妹 提交于 2019-11-26 19:30:13
My issue is that I have a bunch of WordPress websites in my git repo, of which I want to selectively commit only the content of my themes folders, while ignoring the rest of the redundant files found in WordPress. I've used .gitignore files to ignore file types before, but can it be used the other way around- that is to ignore everything BUT a certain folder path? root (git repo) - / wordpress - - / (WordPress Site 1)/wp-content/themes - - / (WordPress Site 2)/wp-content/themes - - / (WordPress Site 3)/wp-content/themes Thanks- UPDATE: Based on the answers I did the following, but it's not

Ignoring a directory from a Git repo after it's been added

蹲街弑〆低调 提交于 2019-11-26 19:17:43
问题 I've learned how to exclude an entire directory in git (add a line bin/ to .gitignore ). And I've learned how to ignore files "after the fact" (i.e. after they have been added to git): git rm --cached <filename> How do I ignore an entire directory (e.g. bin/ ) after it has been added to a Git repo? I tried git rm --cached bin/ but all I received was the error: fatal: pathspec 'bin/' did not match any files When I tried (at the root directory, where .git exists) git rm --cached MyProj/bin/ the

Correctly ignore all files recursively under a specific folder except for a specific file type

。_饼干妹妹 提交于 2019-11-26 19:13:29
问题 I have seen similar questions (1, 2 and 3), but I don't get a proper solution from them. I need to ignore all files under a particular folder except for a specific file type. The folder is a subdirectory for the root path. Let me name the folder Resources . Since I don't want to complicate things, let me ignore files under all folders named Resources wherever it is. This is the most common solution (in all the duplicate questions) # Ignore everything * # Don't ignore directories, so we can

Extended regular expressions (ERE) for .gitignore

孤人 提交于 2019-11-26 18:21:23
问题 Is there a way to use extended regular expressions(ERE) in a .gitignore file? For example I want to use the + repetition character in a .gitignore file. Is there a way to do that? 回答1: As illustrated here and detailed in "this question", the function fnmatch() is involved to interpret glob patterns, which means regular expressions are not supported. This is what gitignore man page mentions: Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM

Git Ignores and Maven targets

橙三吉。 提交于 2019-11-26 17:55:22
问题 Anyone know if it is possible to ignore all the instances of a particular directory in a file structure managed by git. I'm looking to exclude all the 'target' folders in a maven project with a number of submodules. I know I can explicitly exclude each of them in a top level .gitignore, but I'd really like to be able to specify a pattern like **/target/* there to have it automatically ignore the instance in sub directories? Is this possible? 回答1: It is possible to use patterns in a .gitignore

How do negated patterns work in .gitignore?

爱⌒轻易说出口 提交于 2019-11-26 17:33:38
I am attempting to use a .gitignore file with negated patterns (lines starting with !), but it's not working the way I expect. As a minimal example, I have the folllowing directory structure: C:/gittest -- .gitignore -- aaa/ -- bbb/ -- file.txt -- ccc/ -- otherfile.txt and in my gitignore file, I have this: aaa/ !aaa/ccc/ My understanding (based on this doc page ) is that the file aaa/ccc/otherfile.txt should not be ignored, but in fact git is ignoring everything under aaa. Am I misunderstanding this sentence: "An optional prefix ! which negates the pattern; any matching file excluded by a