git与重命名的文件合并 [英] git merge with renamed files

查看:908
本文介绍了git与重命名的文件合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型网站,我正在进入一个新的框架,并在这个过程中添加git。当前网站没有任何版本控制。



我开始将网站复制到新的git存储库中。我做了一个新的分支,并完成了所有需要的改变,以使它能够与新框架一起工作。其中一个步骤是更改所有页面的文件扩展名。



现在我一直在处理新网站的工作,对文件进行了更改旧的网站。因此,我切换到掌握并复制了所有这些变化。



问题是,当我将分支与新框架合并回主模块时,每个文件都有冲突这在主分支上被更改了。



我不会担心它,但有几百个文件会发生更改。我已经试过 git rebase git rebase --merge 没有任何运气。



如何合并这两个分支而不处理每个文件?

解决方案

我找到了一个修复程序。由于文件的重命名是通过脚本完成的,我能够复制新的.php文件并在合并之前重新运行脚本。由于这些文件具有相同的名称,所以合并工作时不会发生冲突。



以下是整个过程的步骤。


  1. 创建git repo git init

  2. 复制
    中的现有文件
  3. 提交

  4. 运行脚本以重命名文件 check it out

  5. 确保修改在您提交时进行更改

  6. 签出您在步骤6中创建的分支

  7. 复制文件的新版本

  8. 运行脚本以重命名文件(这将替换第一次运行的文件)
  9. 提交

  10. 结帐大师

  11. 将分支合并到master中

这是有效的,因为git使用新名称对文件进行了更改。


I have a large website that I am moving into a new framework and in the process adding git. The current site doesn't have any version control on it.

I started by copying the site into a new git repository. I made a new branch and made all of the changes that were needed to make it work with the new framework. One of those steps was changing the file extension of all of the pages.

Now in the time that I have been working on the new site changes have been made to files on the old site. So I switched to master and copied all of those changes in.

The problem is when I merge the branch with the new framework back onto master there is a conflict on every file that was changed on the master branch.

I wouldn't be to worried about it but there are a couple of hundred files with changes. I have tried git rebase and git rebase --merge with no luck.

How can I merge these 2 branches without dealing with every file?

解决方案

I figured out a fix. Since the renaming of the files was done by a script I was able to copy the new .php files and rerun the script before the merge. Since the files had the same name the merge worked without conflicts.

Here are the steps for the whole process.

  1. Create git repo git init
  2. Copy existing files in
  3. Commit
  4. Run script to rename files
  5. Commit
  6. Create a branch but don't check it out
  7. Make fixes committing changes as you go
  8. Checkout the branch you made in step 6
  9. Copy the new versions of the files
  10. Run the script to rename the files (this should replace the ones from the first run)
  11. Commit
  12. Checkout master
  13. merge the branch into master

This works because to git the changes were made to the files with the new name.

这篇关于git与重命名的文件合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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