如何“分割”文件与Git [英] How to "split" files with git

查看:118
本文介绍了如何“分割”文件与Git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我必须在开发分支上关注文件:

 #file.rb 

class Code
def methodA
'aA1'
end
def methodB
'bB2'
结束
结束

但在我的主分支分支上我想将这些方法分成不同的文件:

 #in file.rb 
class Code
def methodA
'aA1'
end
end

#in extra.rb
class代码
def methodB
'bB2'
end
end

我可以简单地创建文件在开发上,然后签出到 master ,重新绑定并手动分开文件,但是可以进行设置,以便在更改开发它会被转移到 master 文件的右侧部分 >

解决方案

要将分割结转到' master '意味着Git能够检测到分割。



并且如最近的帖子(本月:2009年5月),Git还没有完成。

这可能适用于其中有一小部分的大文件被分割到另一个文件,但对于小文件而言,内容对于git重命名检测器来接受更改显得太不同。



因此重新设定' master '位于开发 push )' master ',因为' development ',因为这样的操作( rebase )会重写'<$ c $提交的SHA-1 c> master '分支(因为它们被重放在' development 'branch)



正如我在 rebase vs.merge ,如果你的开发分支不是太远的话(就主从修改而言,另一种策略是将开发放在顶端的主,进行分割,然后将开发合并回主(此时快进合并)。

If I had to following file on my development branch:

# file.rb

class Code
 def methodA
  'aA1'
 end
 def methodB
  'bB2'
 end
end

but on my master branch I wanted to separate the methods into different files:

# in file.rb
class Code
  def methodA
    'aA1'
  end
end

# in extra.rb
class Code
  def methodB
    'bB2'
  end
end

I could simply create the file on development, then checkout to master, rebase and separate the file manually, but is it possible set things up so that when I make changes to development it would be carried over to the right "part" of the file on master?

解决方案

To have a split "carried over to the right "part" of the file on 'master'" would imply Git being able to detect the split.

And as illustrate by this recent thread (this month: May 2009), Git is not quite there yet.
That might work for big files with a small part in it split to another file, but for small files, the content appears "too different" for git rename detector to pick up the changes.

So rebase 'master' on top of 'development' might work, provided you did not publish (push) 'master' since 'development' has been made, because such an operation (rebase) will rewrite the SHA-1 of commits on 'master' branch (since they are replayed on top of commits of the 'development' branch)

As I described in rebase vs.merge, if your development branch is not "too far" (in term of modifications from master, another strategy would be to rebase development on top of master, make the split, and then merge development back to master (fast-forward merge at this point)

这篇关于如何“分割”文件与Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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