Git-防止某个特定的提交被推送 [英] Git - preventing a particular commit from ever being pushed

查看:249
本文介绍了Git-防止某个特定的提交被推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将git和Source Tree一起使用.

I am using git with Source Tree.

我已经对分支的本地副本中的某些文件进行了3-4次更改.我将始终需要在本地进行这些更改,但是我永远不要将其意外地推到远程位置.我当然可以不提交这些更改,但是那样的话,如果意外丢弃或清洁等情况,我可能会丢失更改.

I have made 3-4 changes to some files in a local copy of a branch. I will always need these changes locally but I want to never accidentally push it to remote. I can of course keep these changes uncommitted, but that way I risk losing the changes in case of an accidental discard or clean etc.

有什么办法可以将某些文件标记为永不推送.

Is there any way I can mark some files for never being pushed.

或者有什么更好的方法可以实现我的目的.

Alternately is there any better way to achieve my purpose.

其中一些是文件更改&我已将一些新文件添加到本地存储库中

Some of these are file changes & some of these new files I have added to the local repository

推荐答案

对不起,但有人必须告诉你真相.你不能做你想做的事.

I am sorry but someone has to tell you the truth.. You cannot do what you want.

您无法阻止提交,除非它位于另一个未推送的分支中.但是在这种情况下,您当然不会在同一个地方同时拥有 Thefiles 和您的dev分支.

You simply cannot prevent a commit from being pushed, unless it is in another, not pushed branch. But in this case of course you won't have both The Files and your dev branch in the same place.

您不想要的答案

对于新文件,正如其他人所说,您可以忽略它们.

For new files, as others said, you can ignore them.

对于已经被跟踪的文件,您可以使用git update-index --assume-unchanged <file>告诉git忽略本地修改,但这不会阻止git放弃带有检出的更改.

For already tracked files you can tell git to ignore local modifications with git update-index --assume-unchanged <file>, but this won't prevent git from dropping changes with a checkout, for example.

您可以做什么

我认为唯一的选择是更改应用程序加载这些文件的方式(我假设它们类似于配置文件).

I think that the only option is to change how your application loads those files (I assume that they are something like configuration files).

例如,有一个可配置的 local 文件夹,可以在其中找到其他属性文件.该文件夹将在存储库外部,并且可能在另一个存储库中,或使用其他服务进行备份

For example have a configurable local folder where other property files can be found. This folder would be outside the repository, and maybe in another repository or backed up with other services

这篇关于Git-防止某个特定的提交被推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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