Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将blob临时添加到git存储库_Git - Fatal编程技术网

将blob临时添加到git存储库

将blob临时添加到git存储库,git,Git,我需要将一些二进制文件添加到Git存储库中一段时间。 (实际上,它们是ODT文档,我希望连续转换为可版本的LaTeX源文件。我希望它们出现在repo中,因为我在多台计算机上工作,并且与其他计算机共享一些工作)。 但我希望这些二进制文件在我不再需要它们时被删除。 也许这不是一个真正的问题,但为了一致性,我更愿意将它们从回购协议中清除 所以我的想法是创建一个新的分支,并向其中添加二进制文件,因此所有使用这些文件的提交都在这个分支的上下文中 如果我随后使用git branch-D删除此分支,这些文件是

我需要将一些二进制文件添加到Git存储库中一段时间。 (实际上,它们是ODT文档,我希望连续转换为可版本的LaTeX源文件。我希望它们出现在repo中,因为我在多台计算机上工作,并且与其他计算机共享一些工作)。 但我希望这些二进制文件在我不再需要它们时被删除。 也许这不是一个真正的问题,但为了一致性,我更愿意将它们从回购协议中清除

所以我的想法是创建一个新的分支,并向其中添加二进制文件,因此所有使用这些文件的提交都在这个分支的上下文中


如果我随后使用git branch-D删除此分支,这些文件是否会消失,或者作为其历史记录的一部分仍在回购中?

它们在一段时间内仍将是隐藏历史记录的一部分:

当分支将被删除时,包含文件的提交将变得不可访问,即在查看历史记录时无法访问。它们在对象存储中,但是如果没有git魔法,没有人可以查看它们。此外,在执行获取/拉取/克隆操作时也不会检索到它们


在运行一些
git gc
后,这些提交将被清除,这将删除超过2周的不可访问的提交。

在一段时间内,repo中仍会有提交

首先,即使分支被删除,提交仍然存在,并在HEAD reflog中引用(这是HEAD最近被删除的位置)。您可以在
.git/logs/HEAD
中看到这一点
通常,reflog会在30天后终止无法访问的引用(从HEAD或任何分支)。您可以强制reflog以过期

然后,一旦reflog没有引用这些提交,它们将不会被删除,直到调用或为止
git gc
将自动删除两周前创建的每个悬空(意味着它们不会在任何地方被引用)提交/blob


无论如何,在您的特定情况下,如果您不想在回购协议中使用这些文档,这可能是一个很好的迹象,表明您不应该首先将它们放在这里,并且git不是解决您问题的方法


我想像dropbox/google drive/等这样的解决方案更合适。

我尝试了使用原始问题的第一条注释,我想分享我的测试结果

如果您将OpenOffice文档保存为“平面XML”,您将获得一种可在Git中使用的可扩散文件格式。 虽然这是可行的,但它还远远不够完美,因为有相当多的开销不是“内容”,而是配置信息,如时间戳、视口信息以及可视按钮或其状态等。 其中很多内容也涉及到提交。 这是将一个段落插入空文档的区别:

diff --git a/Test2.fodt b/Test2.fodt
index 02a528a..bec4f67 100644
--- a/Test2.fodt
+++ b/Test2.fodt
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>

 <office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
- <office:meta><meta:creation-date>2013-02-26T08:36:00</meta:creation-date><meta:generator>LibreOffice/3.6$Linux_x86 LibreOffice_project/360m1$Build-2</meta:generator><meta:document-statistic meta:table-count="0" meta:image-count="0" meta:object-count="0" meta:page-count="1" meta:paragraph-count="0" meta:word-count="0" meta:character-count="0" meta:non-whitespace-character-count="0"/></office:meta>
+ <office:meta><meta:creation-date>2013-02-26T08:36:00</meta:creation-date><meta:generator>LibreOffice/3.6$Linux_x86 LibreOffice_project/360m1$Build-2</meta:generator><meta:document-statistic meta:table-count="0" meta:image-count="0" meta:object-count="0" meta:page-count="1" meta:paragraph-count="1" meta:word-count="2" meta:character-count="13" meta:non-whitespace-character-count="12"/><dc:date>2013-02-26T08:37:13</dc:date><meta:editing-duration>P0D</meta:editing-duration><meta:editing-cycles>1</meta:editing-cycles></office:meta>
  <office:settings>
   <config:config-item-set config:name="ooo:view-settings">
    <config:config-item config:name="ViewAreaTop" config:type="int">0</config:config-item>
@@ -14,7 +14,7 @@
     <config:config-item-map-entry>
      <config:config-item config:name="ViewId" config:type="string">view2</config:config-item>
      <config:config-item config:name="ViewLeft" config:type="int">6158</config:config-item>
-     <config:config-item config:name="ViewTop" config:type="int">2501</config:config-item>
+     <config:config-item config:name="ViewTop" config:type="int">2988</config:config-item>
      <config:config-item config:name="VisibleLeft" config:type="int">0</config:config-item>
      <config:config-item config:name="VisibleTop" config:type="int">0</config:config-item>
      <config:config-item config:name="VisibleRight" config:type="int">29314</config:config-item>
@@ -205,6 +205,12 @@
   <text:linenumbering-configuration text:number-lines="false" text:offset="0.499cm" style:num-format="1" text:number-position="left" text:increment="5"/>
  </office:styles>
  <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
+   <style:text-properties officeooo:paragraph-rsid="0004a3d7"/>
+  </style:style>
+  <style:style style:name="T1" style:family="text">
+   <style:text-properties officeooo:rsid="0004a3d7"/>
+  </style:style>
   <style:page-layout style:name="pm1">
    <style:page-layout-properties fo:page-width="21.001cm" fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" fo:margin="2cm" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:footnote-max-height="0cm">
     <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" style:line-style="solid" style:adjustment="left" style:rel-width="25%" style:color="#000000"/>
@@ -224,7 +230,8 @@
     <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
     <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
    </text:sequence-decls>
-   <text:p text:style-name="Standard"/>
+   <text:p text:style-name="P1"><text:span text:style-name="T1">One paragraph</text:span></text:p>
+   <text:p text:style-name="P1"><text:span text:style-name="T1"/></text:p>
   </office:text>
  </office:body>
 </office:document>
\ No newline at end of file
diff--git a/Test2.fodt b/Test2.fodt
索引02a528a..bec4f67 100644
---a/Test2.fodt
+++b/Test2.fodt
@@ -1,7 +1,7 @@
-2013-02-26T08:36:00LibreOffice/3.6$Linux\u x86 LibreOffice\u项目/360m1$Build-2
+2013-02-26T08:36:00LibreOffice/3.6$Linux\u x86 LibreOffice\u项目/360m1$Build-22013-02-26T08:37:13P0D1
0
@@ -14,7 +14,7 @@
视图2
6158
-     2501
+     2988
0
0
29314
@@ -205,6 +205,12 @@
+  
+   
+  
+  
+   
+  
@@ -224,7 +230,8 @@
-   
+一段
+   
\文件末尾没有换行符

FWIW,最近的Open/LibreOffice版本允许保存为可版本化的基于文本的XML ish格式(
.fodt
)。这些文件往往相当大,但我在
git
中成功地跟踪了这些文件。当然,我没有尝试过合并它们(我的电子表格往往比我的实际代码项目有更多的线性历史)-不确定这是否有效。谢谢你的信息。我不知道,但我会用临时回购做一些实验。也许这也行。如果提交的内容能显示从OOo到LaTeX的变化,那就太好了……也许你是对的,但我会看看我能对其他评论做些什么