使用--skip-worktree从另一个分支处理对文件的更改 [英] Handling changes to files with --skip-worktree from another branch

查看:105
本文介绍了使用--skip-worktree从另一个分支处理对文件的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的机器上,我已将-skip-worktree 设置为 config / database.yml 。 / p>

On my machine, I've set --skip-worktree to config/database.yml.

git update-index --skip-worktree config/database.yml

另一位开发人员已提交并合并到develop分支中,对 config / database.yml 的更改项目。

Another developer has committed and merged into the develop branch changes to config/database.yml while working on the project.

现在,当我执行 git pull源开发时,我得到

Now, when I do git pull origin develop, I get

Andrews-Air:[project] agrimm$ git pull origin develop
From bitbucket.org:[company]/[project]
 * branch            develop    -> FETCH_HEAD
Updating [SHA]..[Another SHA]
error: Your local changes to the following files would be overwritten by merge:
    config/database.yml
Please, commit your changes or stash them before you can merge.
Aborting

我应该如何处理此类更改?我应该这样做

How should I handle such a change? Should I do

git update-index --no-skip-worktree config/database.yml
git stash save "Save changes to config/database.yml"
git pull origin develop
git stash apply
# Fix any conflicts
git update-index --skip-worktree config/database.yml

还是没有那么简单的方法?

Or is there a less hacky approach?

推荐答案

那根本不是一个骇人听闻的方法。在这种情况下,这实际上就是您需要做的。让我们逐步介绍该方案。 (因为它是一个YML文件,所以在此过程中作了一些假设。)

That isn't a hacky approach at all. It's actually exactly what you need to do in this situation. Let's go through the scenario step by step. (Making a few assumptions along the way because it's a YML file.)

您忽略了该文件,因为您所做的更改仅影响本地构建过程,而不会不想将这些更改推给其他人,并可能影响它们,或者更糟糕的是,影响生产。

You're ignoring the file because you have changes that only affect your local build process and don't want to accidentally push those changes to others and potentially affect them or, worse yet, production. A fairly normal and good practice.

有时候,确实需要更改这些文件,所以在这种情况下,必须提交更新的版本。进行这些更改将触发检查,以验证其覆盖的文件与提交中的文件匹配,如果不匹配,则抛出错误。 (完整性检查失败将忽略该标志)。

Sometimes these files do need to be changed, as in this situation, so an updated version gets committed. Pulling in these changes will trigger a check to verify that the file it's overwriting matches the one in the commit and, if not, it throws the error. (Failing the integrity check will ignore the flag)

您正在主动忽略该文件,因此您需要让git再次关注它。否则,没有git进程将看不到该文件。

You're actively ignoring the file, so you need to tell git to care about it again. Otherwise no git process will see the file.

git update-index --no-skip-worktree config/database.yml

然后将您的更改放在安全的地方,并且由于您不想提交更改,因此隐藏是最好的位置:

Then put your changes somewhere safe, and since you don't want to commit them, stash is the best place:

git stash save "Save changes to config/database.yml"

您终于可以将更改从远程引入本地分支机构。遇到原始错误时,您已经抓取了信息,因此也可以进行合并。因此:

You can finally bring the changes from the remote into your local branch. You've already fetched when you got the original error, so you can also just do the merge. So:

git pull origin develop
 -or-
git merge origin/develop

您现在是最新的,但是您仍然希望这些更新能够在本地运行,所以让我们把它们找回来从我们的安全存储位置:

You're up to date now, but you still want those updates to make it work locally, so let's get them back from our safe storage place:

git stash pop

如果有任何冲突,您可以解决它们,并确保在集成新更改后您的项目将正确构建。

If there are any conflicts, you can resolve them and make sure your project will build correctly after integrating the new changes.

最后,我们想再次保护其他用户免受我们的本地更改,因此我们恢复了路径上的skip-worktree标志。

Finally, we want to protect the other users from our local changes again, so we reinstate the skip-worktree flag on the path.

git update-index --skip-worktree config/database.yml

我们完成了

这篇关于使用--skip-worktree从另一个分支处理对文件的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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