How to permanently prevent specific part of a file from being committed in git?

后端 未结 6 553
一个人的身影
一个人的身影 2020-12-10 04:07

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

6条回答
  •  旧巷少年郎
    2020-12-10 04:34

    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

提交回复
热议问题