Git推提醒/帮手? [英] Git push reminder/helper?

查看:90
本文介绍了Git推提醒/帮手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我需要(为了使我的开发更快)在我的代码中编码一些东西。这可能是证书,或者可能只是一个黑客,让我测试某些功能。出于很多原因,我从来不想将这些代码推送到主代码库甚至开发分支。一段时间以来,我一直在使用'git-assume-unchaged'命令,但是在合并,rebase等可能混淆后,你可能会推动你不想要的东西。有没有一个很酷的干净方式来实现这一目标?也许有些命令提醒我必须记得在推送之前签出一些文件或类似的东西?有任何想法吗?

解决方案

在许多情况下(比如凭证),我会建议考虑如何避免必须将这些 - 进入源代码控制的文件。 (这可能最终会以其他方式帮助你。)但是,可能有些情况下临时代码对你来说是最直接的工作流程,所以......

一种解决方案是使用 pre-commit 钩子。你可以用注释标记你的临时代码(类似于 // xxxTEMPxxx 类似于C语言),然后拒绝在diff中找到你的标记的任何提交。请参阅 .git / hooks / pre-commit.sample 中的示例。



然后,您可以保留更改在你工作,提交或做任何事情的地方,但如果你 git add 这个变化,那么你会被提醒它已经存在并且可以取消它。 (如果您正在处理同一个文件中的其他代码,可以使用 git add -p 来选择性地将您打算提交的更改分阶段执行,同时保留临时代码。 )



当然,你的临时变化仍然存在于未跟踪的变化中,这可能妨碍某些操作。但在这种情况下,你可以把它们藏起来。至少比尝试玩承担 - 不变要好。


Sometimes I need (in order to make my development faster) harcode some stuff in my code. That can be credentials, or maybe just a hack to allow me to test certain feature. For many reasons, I never want to push this code to the main codebase or even the development branch. For some time I've been using the 'git-assume-unchaged' command but after merges, rebases, etc that can get mixed up and you might be pushing something you don't want. Is there a cool clean way to achieve this? maybe some command that warns me that I have to remember to checkout some file before pushing or something like that? any ideas?

解决方案

In many cases (like credentials) I would suggest thinking about ways in which you can avoid having to put those - even temporarily - into source-controlled files. (This might end up helping you in other ways as well.) But there may just be cases where temporary code is the most straightforward workflow for you, so ...

One solution would be to use a pre-commit hook. You could mark your temporary code with a comment (something like // xxxTEMPxxx in C-like languages maybe) and then reject any commit that finds your marker in the diff. See the example in .git/hooks/pre-commit.sample.

You can then keep your change in place as you work, committing or doing whatever, but if you git add the change then you'll be reminded that it's there and can unstage it. (If you're working on other code in the same file, you can use git add -p to selectively stage the changes you intend to commit while keeping your temp code out.)

Of course your temp changes still exist as untracked changes, which can get in the way of some operations; but in that case you can stash them. It's got to be better than trying to play with assume-unchanged at least.

这篇关于Git推提醒/帮手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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