这是我的用例:
我正在编写一个如下所示的部署脚本:
cd /project-deployment-dir
git stash --include-untracked
git pull
git stash pop
如果我没有用符号链接替换存储库中的某些文件,那么它会工作正常。例如。
var/storage => /nfs/project-1/storage
var/cache => /tmpfs/project-1/cache
而这是在存储库中:
var/storage/images/.gitkeep
var/storage/documents/.gitkeep
有没有办法告诉git stash
并git pull
跳过某个文件夹并使其保持不变。
或者更好的是,跳过所有符号链接并使其保持不变?
编辑:
第一个 stash 命令给了我以下错误:
error: 'var/storage/documents/.gitkeep' is beyond a symbolic link
fatal: Unable to process path var/storage/documents/.gitkeep
Cannot save the current worktree state
编辑2:
我也尝试使用,git pathspec
但效果也是不正确的,事实上它非常奇怪,我甚至不明白为什么会发生这种情况:
$ git status
On branch release/4.23.0
Your branch is up to date with 'origin/release/4.23.0'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: var/storage/order-documents/.gitkeep
deleted: var/storage/printer-files/.gitkeep
Untracked files:
(use "git add <file>..." to include in what will be committed)
.updating
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash push --include-untracked -- ':(exclude)var/storage'
Saved working directory and index state WIP on 4.23.0: ccd3357 Update composer.lock
fatal: empty string is not a valid pathspec. please use . instead if you meant to match all paths
$ git stash push --include-untracked -- . ':(exclude)var/storage'
Saved working directory and index state WIP on 4.23.0: ccd3357 Update composer.lock
The following paths are ignored by one of your .gitignore files:
var
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"
$ git status
On branch release/4.23.0
Your branch is up to date with 'origin/release/4.23.0'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .updating
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: var/storage/order-documents/.gitkeep
deleted: var/storage/printer-files/.gitkeep
$ git version
git version 2.34.1
我的文件(在本例中只是)没有被存储,而是.updating
被暂存了。此外,我必须提供正路径规范,尽管从 git v2.12 开始显然不再需要它。
答案1
从 有用的 Git 命令:
忽略符号链接
将所有符号链接添加到您的.gitignore
:
find . -type l >> .gitignore
从存储库中删除所有符号链接
find . -type l -exec git rm --cached {} \;
其他有用的命令也可以在此链接中找到。