Git ignore local changes to portions of tracked files

后端 未结 4 1138
死守一世寂寞
死守一世寂寞 2020-12-04 09:07

Specifically, I maintain a git repository of my dotfiles. I recently started working on a new machine and cloned my repository on the same.

Now, I wish to make some

相关标签:
4条回答
  • 2020-12-04 09:39

    Here is an alternative solution to your specific problem. Place machine-config configuration in a ~/.gitconfig.local file, and then put the following in your version-controlled ~/.gitconfig:

    [include]
        path = ~/.gitconfig.local
    

    This will tell Git to treat anything it finds in ~/.gitconfig.local as if it were in ~/.gitconfig. Yes, you can override settings. No, it does not require the file to exist (Git will silently ignore the setting if there is no ~/.gitconfig.local).

    See here for more information about [include].

    I follow this strategy in my configurations for Emacs, Zsh, Git, Tmux, etc., so that they are customizable without the need to modify version-controlled files. To accomplish this, I have init.local.el, .zshrc.local, .gitconfig.local, .tmux.local.conf, and so on.

    0 讨论(0)
  • 2020-12-04 09:44

    As suggested by Peter you can keep those machine specific changes in a branch. Obviously you will have to be careful to strictly separate changes to those machine specific files from the "mainline". There are 2 ways for doing this:

    1. Keep rebasing the branch whenever you change the mainline (this would be my preference)
    2. Keep merging mainline changes into the branch (but obviously never merge in the other direction)
    0 讨论(0)
  • 2020-12-04 09:46

    I don't believe there's a specific command that will 'untrack' certain changes to a file. However, there's no reason that you couldn't create a local branch into which you pull changes from your remotes, but never send any changes back.

    0 讨论(0)
  • 2020-12-04 09:48

    Try using this command:

    git update-index --assume-unchanged FILENAME_TO_IGNORE
    

    To reverse it (if you ever want to commit changes to it), use:

    git update-index --no-assume-unchanged
    

    UPDATE:

    Here's how to list 'assume unchanged' files under current directory:

    git ls-files -v | grep -E "^[a-z]"
    

    As the -v option will use lowercase letters for 'assume unchanged' files.

    0 讨论(0)
提交回复
热议问题