使用git管理仅限本地的更改 [英] Managing local-only changes with git

查看:92
本文介绍了使用git管理仅限本地的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地分支上,我对Makefile进行了一些个人(仅限本地)的更改(只是更改了编译器的路径)。很明显,我不想承诺这些更改,因为它们只与我有关。但是,如果我没有提交它们,那么当我尝试与远程分支同步时会出现错误:

 %git获取上游
%git合并上游/主
错误:您对Makefile的本地更改将被合并覆盖。中止。
请在您合并之前提交您的更改或存储它们。

每次发生这种情况时,存储并取消存储文件似乎很乏味。例如,在Perforce中,您只需将这些文件移到单独的更改列表中,并在必要时解决合并冲突。



我想要发生的事情是让git自动合并我的本地Makefile和远程的(如果可能的话),但不必提交它。我怎么会这样做?

解决方案

有几种方法可以解决这个问题,这是我的想法。 >

创建一个新的 makefix 分支并在那里提交makefile。无论何时您需要制作项目,切换到该分支。您可以在 master 中工作,只需保持合并,或者将 makefix 分支与 master



总体思路是创建一个包含 Makefile 的分支,从来没有被推。



我个人会将 makefix 兑换为 master 所以我的 Makefile 更改始终保持在实际可能的代码之前。



代码示例



  git branch makefix 
git checkout makefix

Makefile

  git add Makefile 
git commit -mAdd本地Makefile更改为编译路径

对于日常工作

  git checkout master 
git fetch upstream
git merge upstream / master

git checkout makefix
git rebase master

这很长很丑,所以我希望别人有更好的方法=]


On my local branch, I have some personal (local-only) changes to a Makefile (just changing the path to the compiler). Obviously I don't want to commit those changes in as they are only relevant to me. However, if I don't commit them then I get an error when I try to sync with the remote branch:

% git fetch upstream
% git merge upstream/master
error: Your local changes to 'Makefile' would be overwritten by merge.  Aborting.
Please, commit your changes or stash them before you can merge.

Stashing and then un-stashing the file every time this happens seems tedious. On Perforce for example, you would just move those file(s) to a separate change list and resolve merge conflicts where necessary.

What I want to happen is for git to automatically merge my local Makefile with the remote one (where possible), but without having to commit it. How would I got about doing that?

解决方案

There are likely several ways to approach this problem, here's my thought.

Make a new makefix branch and commit the makefile there. Whenever you need to make the project, switch to that branch. You can work in master and just keep merging, or rebasing the makefix branch against master.

The general idea is that you're creating a branch containing your Makefile that is never pushed.

Personally I would rebase makefix against master so my Makefile changes always stayed ahead of the actual pushable code. It just feels cleaner in my head.

Code Example

git branch makefix
git checkout makefix

Make your changes to Makefile

git add Makefile
git commit -m "Add Local Makefile Changes to Compiler Path"

For every-day work

git checkout master
git fetch upstream
git merge upstream/master

git checkout makefix
git rebase master

It's long and ugly, so I hope someone else has a better way =]

这篇关于使用git管理仅限本地的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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