Git to ignore. Git folder

I have a php project that uses the linker to manage packages. One of the packages is another project belonging to the same repo. I need to transfer the entire provider folder, but I want to ignore the .git folder in the subproject so that it is not treated as a submodule.

So far I have not been successful. Things I've already tried:

seller / .git

seller/**/. Bastard /

google search

Search


This is what the subproject folder looks like in GitLab. Instead of files, it's just some kind of link.

enter image description here

+5
source share
6 answers

For me, it looks like a design error:

If you download a second project from the same repository as the dependency, this project should be moved to a different repository.

And inside the suppliers directory place another .gitignore file with

# Ignore Git here .git # But not these files... !.gitignore 
+2
source

It seems that git will automatically ignore the .git folders in the subfolders of the root repository.

 (master)[/tmp] $ mkdir test_root (master)[/tmp] $ git init test_root Initialized empty Git repository in /tmp/test_root/.git/ (master)[/tmp] $ cd test test/ test_root/ (master)[/tmp] $ cd test_root/ (master)[/tmp/test_root] (master) $ ls (master)[/tmp/test_root] (master) $ git init test_child Initialized empty Git repository in /tmp/test_root/test_child/.git/ (master)[/tmp/test_root] (master) $ git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) (master)[/tmp/test_root] (master) $ touch test_root_file (master)[/tmp/test_root] (master) $ cd test_child/ (master)[/tmp/test_root/test_child] (master) $ ls (master)[/tmp/test_root/test_child] (master) $ touch test_child_file (master)[/tmp/test_root/test_child] (master) $ cd .. (master)[/tmp/test_root] (master) $ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) test_child/ test_root_file nothing added to commit but untracked files present (use "git add" to track) (master)[/tmp/test_root] (master) $ git add test_child/test_child_file (master)[/tmp/test_root] (master) $ git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: test_child/test_child_file Untracked files: (use "git add <file>..." to include in what will be committed) test_root_file (master)[/tmp/test_root] (master) $ cd test_child/ (master)[/tmp/test_root/test_child] (master) $ git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) test_child_file nothing added to commit but untracked files present (use "git add" to track) (master)[/tmp/test_root/test_child] (master) $ git --version git version 1.9.1 $ git add test_root_file (master)[/tmp/test_root] (master) $ git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: test_child/test_child_file new file: test_root_file (master)[/tmp/test_root] (master) $ git commit -m'1 commit' [master (root-commit) 4d4b695] 1 commit 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test_child/test_child_file create mode 100644 test_root_file (master)[/tmp/test_root] (master) $ git show commit 4d4b69589bf4f471c3c784f95f447d2a40ee6d7d Author: Evgenii Shchemelev Date: Wed Jan 6 09:20:03 2016 +0200 1 commit diff --git a/test_child/test_child_file b/test_child/test_child_file new file mode 100644 index 0000000..e69de29 diff --git a/test_root_file b/test_root_file new file mode 100644 index 0000000..e69de29 
+1
source

You can use git hooks to achieve what you want. Of course, you can use pre-commit to rename the .git directory of your included project, for example. to ".git2", add all the files to the last project except the ".git2" directory, copy everything, click and finally use the post-commit hook to rename the ".git2" folder back to ".git" in your module .

1) Create a pre-commit file under the .git / hooks / of your root account with the contents:

 #!/bin/sh mv "vendor/modulename/.git" "vendor/modulename/.git2" git rm --cached vendor/modulename git add vendor/modulename/* git reset vendor/modulename/.git2 

2) Create a post-commit file under .git / hooks / also with the contents:

 #!/bin/sh mv "vendor/modulename/.git2" "vendor/modulename/.git" 

3) Change the file in your repo and finally

 git commit -a -m "Commit msg" git push 
0
source

Documentation is your friend

Git documentation said that:

Lead ** followed by a slash in all directories. For example, **/foo matches the file or directory foo anywhere, just like the template foo . **/foo/bar matches the file or directory bar anywhere, directly below the "foo" directory.

So you can try the following code to ignore the .git folder in subdirectories:

 **/.git/ 

I also wonder why you are going to ignore the folder and not delete it.

-1
source

You should ignore the entire vendor folder, not just the .git subdirectories. Which packages are used are stored in composer.json and composer.lock , which you check in version control.

See: https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md

If you want to create a reusable package as part of your project, you have two options:

A) Use Composer to process another repo

Add to composer.json ...

 { "repositories": [ { "url": "https://github.com/l3pp4rd/DoctrineExtensions.git", "type": "git" } ], "require": { "gedmo/doctrine-extensions": "~2.3" } } 

B) Use the 2nd package directory

You can create the packages directory and add it to your startup paths. This will allow you to use one Git repository for the entire code (if you want to use two repositories, you can use the Git submodule)

Add to composer.json ...

 "autoload": { "classmap": ["packages"] } 
-1
source

To avoid treating the subfolder as a submodule, delete the .git folder. So you do not see the folder with @number on the website. If you want to update the submodule. You can create a script as described below in Shell

update.sh

 git clone <url> <subfolder that you won't treat it as a module> rm -rf <subfolder>/.git/ git add <subfolder> git commit -m "Updated module" 

update.bat

 git clone <url> <subfolder> rmdir /s /q <subfolder>\.git git add <subfolder> git commit -m "Updated module" 

I believe this is the best way to avoid @number in GitLab

You can submit my GitHub repository , created to answer this question.

-1
source

All Articles