我如何强制git认为文件未被合并? [英] How do I force git to think a file is unmerged?

查看:103
本文介绍了我如何强制git认为文件未被合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对我的回购库中的文件进行更改,然后强制git相信文件未被合并并显示在 git status 中,如下所示:

 #未合并路径:
#(使用git reset HEAD< file> ...来取消)
#(使用git add< file> ...来标记分辨率)

#都修改:lib / delayed / recipes.rb

这是我的整个问题。请阅读关于为什么的解释,因为我知道这是首先要问的问题。



这里的目的是为活塞今天在索引中留下合并冲突,他们很容易被忽略。

方式活塞更新与Git回购协同工作是:


  • 克隆远程回购一个新的临时git回购

  • 检出我们看到的最后一次提交的临时回购(保存在.piston.yml中)

  • 结帐我们的本地回购在新的分支中)到最后一次提交.piston.yml被更新

  • 将我们本地的repo文件复制到temp repo中
  • 提交所有更改在临时repo中(这些是我们在上次更新这个售货项目时的本地更改)

  • 运行 git merge master in临时回购将本地更改与远程回购更改合并在一起

  • IGNORE MERGE CON FLICTS(!)并将所有文件从临时存储库复制到本地存储库中。
  • 将这些文件(在我们的新临时分支中)提交到我们的本地存储库中


  • 将临时分支合并到本地存储库(添加我们所做的任何进一步更改)



我希望通过允许带合并冲突的文件被提交到temp分支来解决这个问题,但在最后(运行 git merge - -squash )我想告诉git关于在temp repo中有合并冲突的文件。

解决方案

在有合并冲突的Git文件中(通常)有索引中的三个版本,以及工作区中带有 diff3 -E / rcsmerge 冲突标记。索引中的版本是共同祖先的第1阶段,我们版本的第2阶段以及他们的版本的第3阶段。对于未合并文件,阶段0中没有版本(您可以使用 git update-index --unresolve 通过删除阶段0来恢复未合并状态)。



您需要使用 git ls-files --stage git ls-tree< commit> 来获得要放入索引的blob(文件版本)的sha-1标识符,或者 git hash-object -w< file> if你想从头开始/从工作区版本生成一个文件的版本。然后你使用 git update-index --index-info 把更高阶的阶段放到索引文件中( git update-index --unresolve 之后,或者在填充更高阶段以从索引中删除阶段0之前 git update-index --force-remove 。您可以使用 git checkout --conflict = merge - < file> 来重新生成合并标记在工作区域中的文件。



HTH(希望帮助)






另见:如何有选择地重新创建合并状态?Git邮件列表上的线程。


I want to make changes to a file in my repo, then force git to believe the file is unmerged and show up in git status like so:

# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#       both modified:      lib/delayed/recipes.rb
#

That's the entirety of my question. Read on for an explanation of why, since I know that's the first thing that will be asked.

The purpose here is a bugfix for Piston which today leaves merge conflicts in the index where they are too easily overlooked.

The way piston update works with a Git repo is:

  • Clone the remote repo into a new temporary git repo
  • Checkout that temp repo to the last commit we saw (saved in .piston.yml)
  • Checkout our local repo (in a new branch) to the last commit where .piston.yml was updated
  • Copy our local repo's files into the temp repo
  • Commit all changes in the temp repo (these are our local changes as of the last time we updated this vendored project)
  • Run git merge master in the temp repo to merge our local changes with the remote repo's changes
  • IGNORE MERGE CONFLICTS(!) and copy all the files from the temp repo to our local repo
  • Commit those files (in our new temp branch) to our local repo
  • Checkout local repo back to our original starting point
  • Merge temp branch into local repo (adds any further changes we have made)

I expect to fix this problem by allowing the file with merge conflicts to be committed into the temp branch, but at the very end (after it runs git merge --squash) I want to tell git about the files that had a merge conflict in the temp repo.

解决方案

In Git file that has a merge conflicts has (usually) three versions in index, and a version in working area with diff3 -E / rcsmerge conflict markers. The versions in the index are stage 1 from common ancestor, stage 2 for "our" version, and stage 3 for "theirs" version. For unmerged file there is no version in stage 0 (you can use git update-index --unresolve to restore unmerged state by deleting stage 0).

You would need to use git ls-files --stage or git ls-tree <commit> to get sha-1 identifiers of blobs (file versions) you want to put in index, or git hash-object -w <file> if you want to generate version of a file from scratch / from working area version. Then you use git update-index --index-info to put higher order stages into the index file (and git update-index --unresolve after this, or git update-index --force-remove prior to stuffing higher stages to remove stage 0 from index). You can re-generate file with merge markers in working area using git checkout --conflict=merge -- <file>.

HTH (Hope That Helps)


See also: "How to selectively recreate merge state?" thread on Git mailing list.

这篇关于我如何强制git认为文件未被合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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