假设没有改变,但只有在下一次更改之前

编程入门 行业动态 更新时间:2024-10-27 10:31:43
本文介绍了假设没有改变,但只有在下一次更改之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何让git忽略当前对文件 foobar 所做的修改,但不会进行任何未来修改?

我在我的工作树中有一个文件,我做了一个小改动,我不想回头。我可以使用 git update-index --assume-foobar ,但随后git将忽略对此文件所做的任何其他更改。

我想告诉git忽略 当前对 foobar 的修改,并警告我是否已经更改其他方式。

因此,在这种情况下,认为 update-index --assume-unchanged 有没有另一种方法告诉git只有当它具有当前内容或当前 mtime 时才能看到 foobar >

解决方案

如何让git忽略当前修改文件 foobar,但没有任何未来的修改?

如果将忽略概念放在比低级商店更高的级别在索引和存储库级别,则可以获得更高的灵活性,而且只需要稍微调整工作流程/流程。

假设我正在处理我的新hello world程序,但是我需要在开发过程中添加一些调试,而这不是我想要成为最终交付。我在这种情况下所做的只是将该更改作为正常提交来检查,但以特殊方式标记它,前缀和后缀提交消息的字符串明显突出于其他提交消息。

$ git checkout - b交付工作交换到一个新分支'交付' $ git rebase -i master

,然后用提交消息的特殊标记来查看提交消除的内容:

pick fdbd12a Mininmal main.c 选择21e3d6f hello world with arg支持选择a62ebac ========= DEBUG:打印argc ======== 选择3160605使用EXIT_SUCCESS pick 0ec0ac6 constify message #Rebase 8ce6878..0ec0ac6到8ce6878 ...

然后给我一个干净的送货分行:

我可以将它合并到我想要交付的任何分支中。

在您的情况下,您可以使用新配置键将更改签入为

git add yourfile git commit -m========新配置键========

,然后只在提交时过滤掉该提交,或者可能有一个单独的分支来处理此提交是唯一区别的地方。例如

git checkout -b computer_new computer_old git add yourfile git commit -m=== =====新配置键========#做一些工作 git commit -am一些工作1 git commit -am一些工作2 git commit -am一些工作3#重新设置NEW CONFIG KEYS作为最新的提交 git rebase -i computer_old

pick xxxxx === =====新配置键======== 选择xxxxx某些工作1 选择xxxxx某些工作2 选择xxxxx某些工作3

pick xxxxx some工作1 选择xxxxx某些工作2 选择xxxxx某些工作3 选择xxxxx ========新配置键========

,然后将这些新工作提交合并回到computer_old

git checkout computer_old git merge computer_new ^

(branch ^意味着一个提交olde r比分支上的最新提交,例如合并到包括有些工作3提交)。

How can I tell git to ignore the current modification made to a file foobar, but not any future modifications?

I have in my worktree a file to which I made a small change that I do not want to commit back. I could use git update-index --assume-unchanged foobar, but then git will ignore any other change made to this file.

I would like to tell git to ignore only the current modification to foobar, and warn me if it has been changed in any other way.

So, considered that update-index --assume-unchanged is not applicable in this case, is there another way to tell git to see foobar as unchanged only as long as it has the current content or the current mtime?

解决方案

How can I tell git to ignore the current modification made to a file foobar, but not any future modifications?

If you place the "ignore" concept on a higher level than the low level store in index and repository level, then you get much higher flexibility and and you only have to adapt your work flow/process a little.

Let's say that I am working on my awesome new hello world program, but I need to add some debug while developing and this is not something I want to become part of the final delivery. What I do in such cases is to just check in that change as a normal commit but mark it in a special way, by prefix and postfixing the commit message with a string that clearly stands out from the other commit messages.

When I some time later want to finish the work I just filter out all those temporarily commits.

$ git checkout -b deliver work Switched to a new branch 'deliver' $ git rebase -i master

and then with the special marking of the commit messages it trivial to see what commits to remove:

pick fdbd12a Mininmal main.c pick 21e3d6f hello world with arg support pick a62ebac ========= DEBUG: print argc ======== pick 3160605 Use EXIT_SUCCESS pick 0ec0ac6 constify message # Rebase 8ce6878..0ec0ac6 onto 8ce6878 ...

Which then gives me a clean delivery branch:

which I can merge into whatever branch I want to deliver to.

In your case you could for instance check in the change with new configuration keys as

git add yourfile git commit -m "======== NEW CONFIG KEYS ========"

and then just filter out that commit when delivering, or possibly have a separate branch to work on where this commit is the only difference. E.g.

git checkout -b computer_new computer_old git add yourfile git commit -m "======== NEW CONFIG KEYS ========" # do some work git commit -am "some work 1" git commit -am "some work 2" git commit -am "some work 3" # Rebase to put "NEW CONFIG KEYS" as the newest commit git rebase -i computer_old

Change from

pick xxxxx ======== NEW CONFIG KEYS ======== pick xxxxx some work 1 pick xxxxx some work 2 pick xxxxx some work 3

to

pick xxxxx some work 1 pick xxxxx some work 2 pick xxxxx some work 3 pick xxxxx ======== NEW CONFIG KEYS ========

and then merge those new work commits back to computer_old

git checkout computer_old git merge computer_new^

(branch^ means one commit older than newest commit on branch, e.g. merge up til including "the some work 3" commit).

更多推荐

假设没有改变,但只有在下一次更改之前

本文发布于:2023-10-12 21:15:20,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!