小编The*_*olf的帖子

Git 签出到外部工作树并删除已删除的文件

我们想要使用 Git 在我们的网络服务器上部署代码。因此,我们在生产服务器上初始化了一个裸存储库。每当我们发布新版本时,我们都会在网站的 DocumentRoot 中执行 git checkout:

git --work-tree=/path/to/webroot/ checkout -f master
Run Code Online (Sandbox Code Playgroud)

在 的子目录中webroot,有几个 Git 不跟踪的文件(缓存文件、用户上传的文件等)。当然,在执行签出时,Git 不能删除这些内容(到目前为止,这部分工作正常)。

然而,Git 也不会删除以前跟踪过但同时被删除的文件(例如,它们在开发过程中因为不再需要而被删除)。目前,此类文件在该过程中仍然存在checkout,从而导致“死”文件的数量稳步增加。有没有办法让 Git 在执行时删除此类文件checkout

编辑-重现步骤:

# create dirs and repos
cd /base/path
mkdir repo.git
mkdir target
cd repo.git && git init

# create, add and commit two files
touch test1.txt
touch test2.txt
git add test1.txt test2.txt
git commit -m testcommit

# checkout to target directory
git --work-tree=../target checkout master -f
# target directory now contains both files …
Run Code Online (Sandbox Code Playgroud)

git dvcs git-checkout

4
推荐指数
1
解决办法
1556
查看次数

标签 统计

dvcs ×1

git ×1

git-checkout ×1