将.git文件夹移动到工作树层次结构中 [英] Move .git folder up in working tree hierarchy

查看:160
本文介绍了将.git文件夹移动到工作树层次结构中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我在我的git repo上完成了其中一项操作(请参阅下面的代码片段),以便将项目有效地移动到文件夹层次结构中的几个文件夹中。这基本上列出了所有文件,并为它们添加了一个前缀文件夹名称,并相应地更新索引。



旧布局:



  + Root 
- Sublevel 1
- Sublevel 2
- .git在这里


新的布局: - .git移动到这里,所以在所有索引文件前加上Sublevel 1 / Sublevel 2 /
- Sublevel 1
- Sublevel 2

$ b

命令:



  git filter-branch --index-filter' 
git ls-files -s | seds-\t-&newRoot / sub1 / sub2 / - |
GIT_INDEX_FILE = $ GIT_INDEX_FILE.new git update-index --index-info&& mv $ GIT_INDEX_FILE.new $ GIT_INDEX_FILE
'HEAD

然而,这个命令,我不知道,只修改了 master 分支。我有大约8个其他分支。当我检出其中一个分支时,它将检查我的回购中的所有文件(大约11,000),它们的原始文件夹结构位于我移动 .git 文件夹。



我该如何修复这个snafu?损坏已经完成。在我运行了 filter-branch 之前,我有一个 .git 文件夹的备份,但是在备份之后我提交了被制造出来的并不多,但足以保证在当前的回购上找到补丁式修复。我没有看到任何明显的针对 filter-branch 命令的特定于分支的参数。

解决方案

filter-branch将只重写命令行中提到的正向引用。所以你需要指定--branches来重写所有分支。你指定了HEAD,所以它只是重写了HEAD(即master)。

在运行filter-branch之后,原始参考文件以refs / original(即refs / original / master在过滤之前是master):对象仍然可用,我相信reflog也保持不变,所以从错误的filter-branch操作中恢复非常简单。



<所以你的选择是:


  • 通过检出master并取消撤消filter-branch命令, git reset --hard refs / original / master

  • 过滤其他分支,以便它们也被转换:重做 filter-branch 命令,但指定 - 分支 - 不是master 而不是HEAD,或者更安全地命名分支为修改明确性



Yesterday I did one of these operations (see code snippet below) on my git repo in order to effectively move my project up a few folders in the folder hierarchy. This basically lists all files and adds a prefix folder name to them and updates the index accordingly.

Old layout:

+ Root
  - Sublevel 1
    - Sublevel 2
      - .git was here

New, desired layout:

+ Root
  - .git moved to here, so prefix all index files with "Sublevel 1/Sublevel 2/"
  - Sublevel 1
    - Sublevel 2

Command:

git filter-branch --index-filter '
    git ls-files -s | sed "s-\t-&newRoot/sub1/sub2/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
    ' HEAD

However, this command, unbeknownst to me, only modified the master branch. I have about 8 other branches off of master. When I checkout one of these other branches, it checks out all files (some 11,000) in my repo in their original folder structure at the new root folder level where I moved the .git folder to.

How do I repair this snafu? The damage is already done. I have a backup of the .git folder before I did ran the filter-branch but I have commits after this backup was made, not many but enough to warrant finding a patch-like fix on the current repo. I don't see any obvious branch-specific arguments to the filter-branch command.

解决方案

filter-branch will "rewrite only the positive refs mentioned in the command line". So you need to specify "--branches" to rewrite all branches. You specified HEAD, so it just rewrote HEAD (i.e. master)

After you run filter-branch, the original refs are backed up in refs/original (i.e. refs/original/master is master before filtering): the objects are still available, and I believe the reflogs are kept intact too, so recovering from a bad filter-branch operation is fairly straightforward.

So your options are:

  • Undo the filter-branch command by checking out master and doing git reset --hard refs/original/master

  • Filter the other branches so they are transformed as well: redo the filter-branch command but specify --branches --not master instead of HEAD, or more safely by naming the branches to be modified explicity

这篇关于将.git文件夹移动到工作树层次结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆