在不同的git分支中维护不同的目录结构 [英] Maintain different directory structure in different git branches

查看:139
本文介绍了在不同的git分支中维护不同的目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git上遇到问题.我有一个项目存储库,该项目正在老化,并想开始一个新版本.我创建了一个新分支(3.0-wip),并删除了文件和文件夹以重新启动.但是,如果我检出master分支,文件和文件夹也将从那里移走.

I had a problem with git. I have a repository of a project that's getting old and want to start a new version. I've created a new branch (3.0-wip) and deleted the files and folders to start again. However, if I checkout my master branch, the files and folders are gone from there too.

我如何拥有自己的存储库,以便我的主分支具有远程存储库所拥有的所有内容,但是我的3.0-wip中的工作目录完全不同,可以在不破坏其他任何分支中的文件和文件夹的情况下修改自己的内容?

How can I have my repository so my master branch has everything the remote repo has, but a completely different working directory in my 3.0-wip that I can modify to my heart's content without destroying the files and folders in any other branch?

推荐答案

已提交在一个分支中的更改不会影响另一个分支.您还需要提交所有删除操作,这就是Dominic试图解释的内容.只需:

Commited changes in one branch do not affect another branch. You need to commit all the deletes as well, that's what Dominic tried to explain. Simply do:

$ git co $NEWBRANCH
$ git status

您将看到不计其数的未删除操作.您必须使用git rm删除文件.
不确定git add --all是否也会处理删除.无论如何,这不是IMO重新开始的最佳方法,因为新分支仍将保留旧的历史.

And you will see zillions of uncommited deletes. You have to use git rm to remove files.
Not sure git add --all will handle deletes as well. Anyway, this is IMO not the best way to start anew as the new branch will still have the old history.

我认为最好创建一个新的断断续续"的提交:

I think it is better to create a new "disconected" commit:

  1. 创建一个新的仓库:mkdir $DIR; cd $DIR; git init
  2. 创建初始提交. touch README; git add --all; git commit -m "Init"
  1. Create a new repo: mkdir $DIR; cd $DIR; git init
  2. Create the initial commit. touch README; git add --all; git commit -m "Init"

现在转到原始存储库,然后:

Now go to to original repo and:

  1. 将其添加为遥控器:git remote add start-anew $DIR/.git
  2. 获取它:git fetch start-anew
  3. 将其放入:git co -b start-anew start-anew/master
  1. Add it as a remote: git remote add start-anew $DIR/.git
  2. fetch it: git fetch start-anew
  3. pull it in: git co -b start-anew start-anew/master

瞧瞧,这是一个拥有空虚历史的分支.

And voila a branch with fresh empty history.

然后,您可能要删除该遥控器,并且还要为该分支机构更改遥控器.到目前为止,我通常是手动编辑.git/config的.

You may want to delete the remote then, and also change the remote for the branch. I am usually editing .git/config manually, so far without an accident.

这篇关于在不同的git分支中维护不同的目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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