How to exclude .gitignore rules only once? - laravel

Make once init of my laravel 8 app on server(ubuntu 20) I need to upload some images under storage, which is excluded
from git by .gitignore rules.
I do not like to remove .gitignore at all, but if there is a way to exclude these rules only once ?
Seems there is some force option, but how can I use it running command locally :
git push -u origin master
and on server :
git pull origin master
?
My root .gitignore:
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
# Node artifact files
node_modules/
dist/
# Compiled Java class files
*.class
# Compiled Python bytecode
*.py[cod]
# Log files
*.log
# Package files
*.jar
# Maven
target/
dist/
# JetBrains IDE
.idea/
# Unit test reports
TEST*.xml
# Generated by MacOS
.DS_Store
# Generated by Windows
Thumbs.db
# Applications
*.app
*.exe
*.war
# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
/public/js/laravel.app.js
/public/js/oneui.app.js
/public/js/tables_datatables.js
/public/css/oneui.css
composer.lock
package-lock.json
.env
vendor/
route_list.txt
Which is correct syntax ?
Thanks!

Looks like adding -f key like:
git add -f storage/app/public/Photos/1/img-13.jpg
works in my case

Related

git apply error no such file or directory

I have two sepearate git repos: A and B. Some repository B files are already present in a subfolder of project A. My goal is to create patches for repo B and then applying them to the subfolder within repo A to conserve history of repo B while merging them. The issue is that a patch is unable to create new files. For example:
assuming this folder structure: /home/user/B/..bunch of directories and /home/user/A/ext/lib/B/..bunch of directories
cd /home/user/B
git format-patch "xx..xx" -o /home/user/A/ (create patch files)
cd /home/user/A
git apply -v --directory=ext/lib/B/ 0001-foo-12345.patch
works fine since the patch is not creating any new files or trying to access a folder which is present in B but not A
BUT
cd /home/user/A
git apply -v --directory=ext/lib/B/ 0002-foo2-6789.patch
does not work and throws this error:
Checking patch ext/lib/B/xyz/test.c...
error: ext/lib/B/xyz/test.c: No such file or directory.
I have tried the following commands so far:
git apply -v --directory=/home/user/A/lib/B/ --include=bb/cc --exclude=cc/ --exclude=bb/ --include=* 0002-foo2-6789.patch
git apply -v --directory=/home/user/A/lib/B/ --include=* --include=bb/cc --exclude=cc/ --exclude=bb/ 0002-foo2-6789.patch
git am --directory=/home/user/A/lib/B/ --include=* --include=bb/cc --exclude=cc/ --exclude=bb/ 0002-foo2-6789.patch
1.create patch file:
git diff --cached >> test.patch
2.use the patch:
git apply -p1 < test.patch
There are a number of ways to create patch files that will create new files. However, creating patches in repo B and applying them in repo A won't import the history of repo B into repo A. Is that what you mean by "conserve history of repo B while merging them"?
Example patch that causes git apply to create a new path:
diff --git a/b1.txt b/b1.txt
new file mode 100644 <-- lines specific to creating new files
index 0000000..12f00e9
--- /dev/null <-- lines specific to creating new files
+++ b/b1.txt
## -0,0 +1 ##
+contents
One way to create patches like this is to copy the files from repo B to their destination in repo A, git add any changed or new files, then use git diff --staged > my.patch to create a patch for all changed and new files. However, by then, the files are already in repo A, so there's little point in creating a such patch, and this also won't import repo B's history into repo A.
If you really want to merge repo B into a subdirectory of repo A and preserver the history of both, you're better off not using patches and looking at the top several answers here: How do you merge two Git repositories?

rsync exclude-from not skipping some items in the list

I have an rsync command like this:
rsync -avz --exclude-from 'exclude-list.txt' -r /source/ destination
the exclude-list.txt looks like this:
.git
src
config.js
.gitlab-ci.yml
.gitignore
local-*
All the listed files and directories are in the same directory as the exclude-list.txt file.
So, the .git, src and config.js are skipped over and not copied (like I want), but the rest of the items are still copied. What's wrong with my syntax? (local-* is supposed to be a wildcard to skip all files beginning with local-).

How to find all empty folders and untracked files when using git?

Based on this post and this post ,
git ls-files --others --exclude-standard can list all untracked files.
But I test it, cannot list empty folder(both tracked and not tracked).
For example,cannot list empty folder archiver folder as below:
.
├── admin.php
├── api
│   ├── index.htm
│   └── remote
│   └── mod
│   ├── index.htm
│   ├── mod_cron.php
│   └── mod_index.php
└── archiver folder
Then my question is: how to list all untracked files and empty folders?
TL;DR: just look for empty directories. You can safely remove them—well, "safe" depends on your own software, but as far as Git is concerned, it's safe. (Watch out for missing files—see the definition of "missing" below—which may remove a directory that Git might want later, but that's sort of OK, because Git will just create it again.)
On a Unix / Linux system (edited to correct lost word in transcription):
find . -name .git -prune -o -type d -empty -print
(at the top level of the work-tree) will find the empty directories.
Long(ish)
Git is not interested in folders / directories. There's no such thing as an untracked folder in the same way that there's no such thing as a tracked folder: Git only cares about files. Specifically, a file is either in the index, or not in the index, and if it's not in the index, it's untracked.
When you use the various options to list untracked files (which tend to skip over ones that are untracked-and-ignored since you normally want that), Git will, sometimes, aggregate together all the files that are in some folder, notice that there are no tracked files in that folder, and report them using the aggregated notation. You can stop this with, e.g., git status --untracked-mode=all; then you'll get the individual file names.
Note that it's possible to have some file that is tracked, yet missing. For instance, suppose sub/README.txt is a tracked file, and actually exists. Then we run rm sub/README.txt. The file sub/README.txt remains in Git's index, and will be in the next commit, but it's missing. If that was the only file in sub in your work-tree, sub is now empty, and you can remove it with rmdir sub. Even though sub/README.txt remains missing (and sub is missing too!), that does not affect the next commit: it will still contain sub/README.txt, because that file is in the index. (Using git rm --cached sub/README.txt, you can remove it from the index too, if that's what you wanted.)
If and when Git goes to copy sub/README.txt back out of the index into the work-tree, Git will, at this point, discover that there is no sub. Git will merely shrug its metaphorical shoulders and create the directory sub, and then put sub/README.txt into it. So this is why Git is not interested in folders / directories: they're just boring and dull, required only when needed to hold files, created on demand.
If you want Git to create a directory, you need to store a file in it. Since programs managed by Git need to be able to ignore the file named .gitignore, this is a very good file name to stick into such a directory. You can write * into that file, and add it to your commits, so that Git will create the directory and write a .gitignore file there containing *, and will thus ignore all additional untracked files within that directory automatically.
Side note: In general, when Git pulls the last file out of some directory, it will remove the directory too, but occasionally I've seen it leave some behind. (Of course, it has to leave the directory behind if it still contains some untracked files. Note that git clean -fd will remove the empty directories, though it also removes the untracked files.)
git ls-files --others --exclude-standard> not_tracked
find . -depth -empty -type d \( ! -regex '.*/\..*' \) >> not_tracked
Please check my answer,I spent 2 days for it.
The command git clean does exactly what you want.

Why is git looking inside vendors directory?

I have the .gitignore file with this code:
/app/cache/*
/app/logs/*
/app/bootstrap*
/vendor/*
/web/bundles/
/app/config/parameters.yml
but when I do :
$ git status
in any situation (before and after add and commit), I get a long text output like this:
...
# deleted: vendor/doctrine/orm/tools/sandbox/cli-config.php
# deleted: vendor/doctrine/orm/tools/sandbox/doctrine
# deleted: vendor/doctrine/orm/tools/sandbox/doctrine.php
# deleted: vendor/doctrine/orm/tools/sandbox/index.php
# deleted: vendor/doctrine/orm/tools/sandbox/xml/Entities.Address.dcm.xml
# deleted: vendor/doctrine/orm/tools/sandbox/xml/Entities.User.dcm.xml
# deleted: vendor/doctrine/orm/tools/sandbox/yaml/Entities.Address.dcm.yml
# deleted: vendor/doctrine/orm/tools/sandbox/yaml/Entities.User.dcm.yml
# modified: vendor/friendsofsymfony/user-bundle/FOS/UserBundle
# modified: vendor/gedmo/doctrine-extensions
# modified: vendor/herzult/forum-bundle/Herzult/Bundle/ForumBundle
# modified: vendor/kriswallsmith/assetic
# modified: vendor/symfony/property-access/Symfony/Component/PropertyAccess/.gitignore
# modified: vendor/symfony/property-access/Symfony/Component/PropertyAccess/StringUtil.php
# modified: vendor/symfony/symfony/CHANGELOG-2.1.md
...
The vendors directory is in .gitignore file, so I don't know what is happening.
I've tried with:
$ sudo git clean -dxf
but nothing changes.
Your vendor directory is checked in to the repo. To remove it, go to your git repo root and run:
git rm -r --cached vendor
This will recursively (due to -r flag) remove vendor from your git repo. The --cached flag will keep the local copy of vendor directory in tact. Note that if there are other devs working with the repo, their copy of the vendor directory will be removed and they will need to bundle install again.
Once you've untracked the directory in git, you can commit the change using:
git commit -m "untrack vendor directory"
Thereafter, .gitignore will happily ignore any changes within the vendor directory next time onwards.
Also, you don't need your entries in .gitignore to begin with a /. Use the / when you want to ensure that only files/folders in root directory are ignored, and any file in a subdirectory matching the pattern should not be ignored.
It looks like you already have files under vendor/* checked in. .gitignore ignores only untracked files. See also the first paragraph in man gitignore.

Git: How to ignore files on Windows?

I create .gitignore in folder with my repository near .git
project
--.git
--.gitignore
--Source
----tmp
----scr
But git doesnt see it, wouldnt ignore files in .gitignore
My .gitignore file:
*.tmp
*~
*.pdb
*.user
*.suo
Sources/tmp
What`s wrong?
Up:
I created new repositiry, add .gitignore before init commit - it work!
But if I add in old repository it doesn`t...
The problem is that you're specifying glob syntax when the default syntax for git is regex.
Try this instead:
.*\.tmp
.*~
.*\.pdb
.*\.user
.*\.suo
Sources\/tmp
What you have should work, though your directory listing has Source/ while your .gitignore has Sources/.
The one thing that springs to mind is that the line endings might not be what git is expecting.
Also, as tmp is a directory, usually a trailing '/' is used:
Source/tmp/
Finally, you can also create a .gitignore in Source/ with the line:
tmp/
instead of having it in the top directory.

Resources