如何不将本地删除的文件提交到git
我们的情况是,我们正在使用git存储大量扫描(图像),并且不希望在设置后将其保存在本地机器上;然而,git将每次本地删除(遵循此过程)视为要提交给回购协议的内容,我们希望这种情况不会发生。有没有关于如何只提交附加文件而不删除任何文件的想法?只需将图像添加到gitignore即可。您不需要将它们存储在repo中,对吗?对于要删除的每个文件,请执行以下操作:如何不将本地删除的文件提交到git,git,Git,我们的情况是,我们正在使用git存储大量扫描(图像),并且不希望在设置后将其保存在本地机器上;然而,git将每次本地删除(遵循此过程)视为要提交给回购协议的内容,我们希望这种情况不会发生。有没有关于如何只提交附加文件而不删除任何文件的想法?只需将图像添加到gitignore即可。您不需要将它们存储在repo中,对吗?对于要删除的每个文件,请执行以下操作: git update-index --assume-unchanged <file> git更新索引--假定未更改 这将阻止G
git update-index --assume-unchanged <file>
git更新索引--假定未更改
这将阻止Git要求您提交删除
话虽如此,也许更好的解决方案是使用SFTP,权限设置为不允许在上传后删除或修改文件。(编辑:将负载打包为一个自包含脚本)
您需要的是一个几乎只有状态的本地存储库,它跟踪您创建的所有内容的存在,但只保留最新内容的内容(在将所有内容推到上游之后)。假设您从未重用过路径名,下面是一个惯例:
一次性设置:
#!/bin/sh
# Git can do "index-only" merges when the content doesn't need to be examined,
# you can casually create sideband indexes, and `git commit-tree` works on any
# tree in the repo.
(
# ^ subshell to keep G_I_F export local
export GIT_INDEX_FILE=.git/sideband-index
# make a merged index that includes everything from both branches, by
# starting from an empty merge base so all files show up as additions.
git read-tree -im $(git mktree </dev/null) worktree everything
# commit to the `everything` branch straight from the constructed index,
# reusing the commit message from `worktree`
git cat-file -p worktree | sed 1,/^$/d \
| git commit-tree -p everything -p worktree $(git write-tree --missing-ok) \
| xargs git update-ref refs/heads/everything
)
git push origin everything
# preserve the branch metadata and, just for safety, your latest images
# by packing it all up:
mkdir -p .git/preserved/pack
rm -f .git/preserved/pack/*
(
git rev-list worktree everything
git rev-parse worktree^{tree} everything^{tree}
git ls-tree -rt worktree | awk '{ print $3 }'
git ls-tree -rt everything | awk '$2 != "blob" { print $3 }'
) \
| git pack-objects .git/preserved/pack/pack
# now for the fun one:
rm -rf .git/objects/* # !!!
# put the preserved stuff back:
mv .git/preserved/pack .git/objects
创建并推送一个everything
分支,跟踪到目前为止您获得的每个图像。基于(仅本地)工作树
分支
git checkout -b everything # this will be the branch you push
git push origin everything # .
git checkout -b worktree # you'll stay on this branch
工作(几乎)就像你不想做任何特别的事情一样:
#!/bin/sh
# Git can do "index-only" merges when the content doesn't need to be examined,
# you can casually create sideband indexes, and `git commit-tree` works on any
# tree in the repo.
(
# ^ subshell to keep G_I_F export local
export GIT_INDEX_FILE=.git/sideband-index
# make a merged index that includes everything from both branches, by
# starting from an empty merge base so all files show up as additions.
git read-tree -im $(git mktree </dev/null) worktree everything
# commit to the `everything` branch straight from the constructed index,
# reusing the commit message from `worktree`
git cat-file -p worktree | sed 1,/^$/d \
| git commit-tree -p everything -p worktree $(git write-tree --missing-ok) \
| xargs git update-ref refs/heads/everything
)
git push origin everything
# preserve the branch metadata and, just for safety, your latest images
# by packing it all up:
mkdir -p .git/preserved/pack
rm -f .git/preserved/pack/*
(
git rev-list worktree everything
git rev-parse worktree^{tree} everything^{tree}
git ls-tree -rt worktree | awk '{ print $3 }'
git ls-tree -rt everything | awk '$2 != "blob" { print $3 }'
) \
| git pack-objects .git/preserved/pack/pack
# now for the fun one:
rm -rf .git/objects/* # !!!
# put the preserved stuff back:
mv .git/preserved/pack .git/objects
所有需要在上游保存的内容都在所有内容
分支上,您已经签出了工作树
。从工作树中删除已处理的图像,在其中创建需要推送的新图像,并提交新的工作树状态:
# work work:
rm -r anything/ you\'re/ done with
create new images
git add -A . # good gitignore patterns make life easy
git commit
要执行请求的工作,请运行
merge-push-and-cleanup # the script below
在这之后,所有的东西都存储在上游,没有多余的东西留在本地,您可以准备更多的工作
合并推送和清理
脚本:
#!/bin/sh
# Git can do "index-only" merges when the content doesn't need to be examined,
# you can casually create sideband indexes, and `git commit-tree` works on any
# tree in the repo.
(
# ^ subshell to keep G_I_F export local
export GIT_INDEX_FILE=.git/sideband-index
# make a merged index that includes everything from both branches, by
# starting from an empty merge base so all files show up as additions.
git read-tree -im $(git mktree </dev/null) worktree everything
# commit to the `everything` branch straight from the constructed index,
# reusing the commit message from `worktree`
git cat-file -p worktree | sed 1,/^$/d \
| git commit-tree -p everything -p worktree $(git write-tree --missing-ok) \
| xargs git update-ref refs/heads/everything
)
git push origin everything
# preserve the branch metadata and, just for safety, your latest images
# by packing it all up:
mkdir -p .git/preserved/pack
rm -f .git/preserved/pack/*
(
git rev-list worktree everything
git rev-parse worktree^{tree} everything^{tree}
git ls-tree -rt worktree | awk '{ print $3 }'
git ls-tree -rt everything | awk '$2 != "blob" { print $3 }'
) \
| git pack-objects .git/preserved/pack/pack
# now for the fun one:
rm -rf .git/objects/* # !!!
# put the preserved stuff back:
mv .git/preserved/pack .git/objects
#/垃圾箱/垃圾箱
#Git可以在内容不需要检查时进行“仅索引”合并,
#您可以随意创建边带索引,`git commit tree`可以在任何情况下工作
#回购协议中的树。
(
#^subshell将G_I_F导出保持在本地
导出GIT_索引_文件=.GIT/边带索引
#创建一个合并索引,其中包含来自两个分支的所有内容
#从空的合并基开始,以便所有文件都显示为添加项。
git read tree-im$(git mktree使用跳过工作树位
该命令提供了一些处理此问题的方法。基于您希望在从工作树中删除Blob时将其保留在历史记录中的假设,您可以使用以下方法:
git add --all
git commit --message="Add new assets to repository."
git update-index update-index --skip-worktree <files ...>
rm <files ...>
您还可以使用查找索引中已从工作树中删除的文件。我有一种预感,Git可能不是解决您问题的理想工具。您几乎可以肯定是正确的;但我目前还不负责这一选择=(顺便问一下,您是否碰巧有到上游repo的文件系统路径?事实上,这个特定的repo是专门针对上述映像的;问题是,一旦它们上升,它们就会从本地被删除,我们不希望随后提交删除。另一个人说git可能不适合这样做,但git的替代方案只是简单而已。)不是作为一个可能的解决方案提交给我们的,所以whee.Shulgooh;我将使用它。你必须对每个提交都这样做吗?我想你必须对每个文件这样做。一旦这样做,它是持久的,还是每次新提交完成时我都必须对每个文件这样做?我稍微戳了一下,更新索引看起来是持久的…can它最终变得太大而无法正常工作?