git:忽略源中的文件

标签 git git-svn gitignore

有没有办法告诉 git 忽略存储在其源中的文件?由于有问题的文件位于上游存储库中,因此仅将它们添加到 .gitignore 或 .git/info/exclude 是行不通的。

背景 :

我的上游存储库中有一些生成的文件。每次我进行本地重建时,这些生成的文件都会更改并且与提交的版本不同。生成的文件在存储库中,因为许多用户没有生成它们的软件(而且我无权更改它)。这些生成的文件永远不会手动生成,我也不想将它们提交到我的 git 存储库。我有一个单独的机制将它们推送到主存储库(我无法控制这个单独的机制)。

我正在使用私有(private) git 存储库对上游颠覆存储库进行编辑。为此,我有一个 git 存储库,仅用于从 subversion 中提取提交。该 git 存储库通过 cronjob 定期同步。然后我有私有(private) git 存储库,它们是上游 git 存储库的克隆。我希望 git 不要让我对生成的文件感到厌烦。我对这两个结果中的任何一个都感到满意:我的本地 git 存储库不再跟踪文件(但它们应该由与 svn 同步的存储库跟踪),或者 git 会静默更新我生成的文件但它永远不会提交我的更改和文件将永远不会显示在“git status”的“已更改但未更新:”部分中。

最佳答案

git update-index --assume-unchanged可能是您的解决方案。查看man page了解更多信息。

  • --assume-unchanged
  • --no-assume-unchanged

  • When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

    This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). You should remember that an explicit git add operation will still cause the file to be refreshed from the working tree. Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

    关于git:忽略源中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1888969/

    相关文章:

    git - 如何避免 GitHub/BitBucket 上的 merge 提交 hell

    Git-SVN 清除授权缓存

    git - "Unable to determine upstream SVN information from working tree history"

    git - 在 Android Studio 3.3.2 中构建 Android 项目后,.gitignore 中存在的文件始终会添加到 git

    git - 从轨道上删除本地 Git 分支的最佳实践?

    git - 具有多个类似项目的修订控制系统(针对同一产品的每个客户定制一个)

    svn - git-svn 能否正确填充 svn :mergeinfo properties?

    git - 为 Symfony2 项目 : why add web/bundles folder to gitignore 设置 GIT

    gitignore - .gitignore 文件中的路径有何不同?

    git - Tig:如何从第一次提交开始查看项目?