从分岔上游原点拉扯时忽略特定文件 [英] Ignore specific files when pulling from forked upstream origin

查看:96
本文介绍了从分岔上游原点拉扯时忽略特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git中,如何从上游源(例如原始项目)拉出某些文件时豁免某些文件?

我有一个我正在开发的项目最初是从非常活跃的存储库中分离出来的。我已经添加了原作为远程命名为上游,以便它可以运行:

  git pull upstream 

并将项目更新到最近的提交。



问题:有一些文件(例如我的 Gruntfile.js ),我不想与原始项目一起更新。每当我拉这些提交,我会得到合并冲突,因为我已经改变了我自己的版本的文件。



我想跟踪这些文件为我自己的本地提交并从我自己的起源拉动变化,因此永久性地将这些添加到 .gitignore 不是一个选项。



我目前的解决方案是暂时添加 Gruntfile.js 和其他到 .gitignore ,从上游拉出来,然后从 .gitignore 中删除​​它们,以便我可以跟踪自己的更改并推送到我的出处。但是,这感觉很尴尬。



有没有什么办法可以忽略这些文件,只是从上游拉出来?

解决方案


git pull是git fetch的缩写,然后是git merge FETCH_HEAD


所以首先你可以做一个,

  git fetch upstream 

后面跟着,

  git merge --no-log --no-ff --no-commit upstream / branch 

在提交之前,Git会停止。因此,您应该能够修改合并,并排除所需的文件。



更新



这些命令可以使用git alias进行组合。



在〜/ .gitconfig中创建一个别名

  [别名] 
fnm =!git fetch upstream&& git merge --no-log --no-ff --no-commit upstream / branch

您可以进一步添加,

  [别名] 
fnm =!git fetch upstream&& git merge --no-log --no-ff --no-commit upstream / branch&& git reset file / path / not / to / be / updated&&& git checkout file / path / not / to / be / updated

使用 git fnm 来完成整个操作。


In git, how do you exempt certain files when pulling from an upstream origin (i.e. the original project)?

I have a project that I'm working on that was originally forked from a repository that is very active. I've added the original as a remote named "upstream" so that it's possible to run:

git pull upstream

and update the project to the most recent commit.

The problem: there are some files (e.g. my Gruntfile.js) that I do not want to update alongside the original project. Whenever I pulled these commits, I would get merge conflicts because I've changed the files in my own version.

I do want to track these files for my own local commits and pull changes from my own origin, so adding these to .gitignore permanently isn't an option.

My current solution is to have a grunt task temporarily add Gruntfile.js and others to .gitignore, pull from upstream, and then remove them from .gitignore so that I can track my own changes and push to my origin. However, this feels hacky.

Is there any way I can ignore these files only when pulling from "upstream"?

解决方案

Yes you can do that.

git pull is shorthand for git fetch followed by git merge FETCH_HEAD

So first you can do a,

git fetch upstream

followed by,

git merge --no-log --no-ff --no-commit upstream/branch

Git will stop before committing. So, you should be able to modify the merge, and exclude the required files.

UPDATE

The commands can be combined using git alias.

Create an alias inside ~/.gitconfig

[alias]
   fnm = !git fetch upstream && git merge --no-log --no-ff --no-commit upstream/branch

You can further add,

[alias]
   fnm = !git fetch upstream && git merge --no-log --no-ff --no-commit upstream/branch && git reset file/path/not/to/be/updated && git checkout file/path/not/to/be/updated

Use git fnm for the complete operation.

这篇关于从分岔上游原点拉扯时忽略特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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