如何永久禁止在git中提交文件的特定部分? [英] How to permanently prevent specific part of a file from being committed in git?

查看:790
本文介绍了如何永久禁止在git中提交文件的特定部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用git-svn克隆了一个远程SVN仓库。我以代码编译的方式修改了此克隆的repo中的pom.xml文件。这个设置对我来说是专属的。因此,我不希望将更改推回远程仓库。



有没有办法阻止文件的这种(部分)更改被提交到回购?我知道这个事实,我可以使用个人分支,但这意味着某些合并开销。有其他方法吗?



我已经看过这个问题,修改只是为了调试purpo>一个,但它们只是用于相当短暂的修改。



更新:我也注意到了。 gitignore的可能性,但这意味着完全排除该文件。

解决方案

编辑:你问的是不可能的,不要看部分部分。
我知道你只能提交部分文件,但你不能忽略文件的某些部分。
您需要使用update-index技巧来避免它处于状态,并且每次您将从远程进行重定位/合并时都需要存储该文件,然后取消修改并忽略您的修改用update-index修改。
我不知道你是否可以为一系列git命令创建一个git别名,所以只需一个命令你就可以执行所有这3个命令来避免麻烦



<请使用.gitignore文件,并且不要将其推送到远程回购:忽略.gitignore文件本身



在.gitignore中,您应该有

  .gitignore 
path / to / pom.xml



<.gitignore文件可以位于工作树的根目录,也可以位于你需要的任何子目录中。


I have cloned a remote SVN repository with git-svn. I have modified a pom.xml file in this cloned repo in a way that the code compiles. This setup is exclusive for me. Thus I don't want to push the changes back on the remote repo.

Is there a way to prevent this (partial) change of a file from being committed into the repo? I'm aware of the fact, that I could use a personal branch, but this would mean certain merging overhead. Are there other ways?

I've looked into this question and this one, but they are for rather temporal changes.

Update: I'm also aware of the .gitignore possibilities, but this would mean to exclude the file completely.

解决方案

EDIT: What you are asking is impossible, I didn't see the "partial" part. I know you can commit only part of files, but you cannot ignore some part of file. You will need to use the update-index trick to avoid having it in the "status" and you will need to stash that file every time you will rebase/merge from the remote, and then unstash your modification and ignore your modification with update-index. I don't know if you can create a git alias for a sequence of git commands so with one command you could do all those 3 commands to avoid the hassle

use a .gitignore file, and don't push it to the remote repo too: Ignore the .gitignore file itself

in your .gitignore, you should have

 .gitignore
 path/to/pom.xml

a .gitignore file can be at the root of the working tree, or in any subdirectory you want/need

这篇关于如何永久禁止在git中提交文件的特定部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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