Git - Temporarily ignore trivial changes to files

前端 未结 4 1325
逝去的感伤
逝去的感伤 2021-01-29 22:22

I\'m looking for a way to \'hide\' minor changes made to a few files in Git, such that they will not show up in git status until a different change is made to those files.

相关标签:
4条回答
  • 2021-01-29 22:56

    There are multiple ways [although may not be clean and neat and would require your attention]

    1. Add the file in concern to .gitignore in your repo so that it doesn't show up for commit. Be careful to remove this from .gitignore when you are ready to commit the file
    2. Ensure you do not 'stage' the file while committing rest of your changes. You may want to write a wrapper over git which will ensure commands like git commit -a or git add . run on all except the file under question. Another alternative would be to use git gui or git citool where you can visually ensure your file isn't in 'staged' area and hence never gets committed
    3. Another way would be to commit all your 'committable' changes and then git stash save your only working file. Later when you are ready to change the file, you can git stash pop and continue working and committing.

    Hope that helps :)

    0 讨论(0)
  • 2021-01-29 23:03

    Just don't add the trivial changes.

    It's good practice to carefully review the things that you add before committing.

    You can even ignore some changes in a file while adding others, using

    git add -p.
    

    This is even easier if you use gitx (R).

    0 讨论(0)
  • 2021-01-29 23:13

    In my use case (developing using an edited config file on my personal machine, running on another machine with the unchanged config), this was the solution for me:

    start ignoring changes to a file:

    git update-index --assume-unchanged path/to/file
    

    keep tracking again:

    git update-index --no-assume-unchanged path/to/file
    
    0 讨论(0)
  • 2021-01-29 23:16

    Keep your changes that are not ready in a separate branch. git rebase this branch atop new changes in the main history as necessary.

    Be it development in progress, temporary things, even things that are never to be included in the main project history -- the same process works equally well.

    If/when the changes of the branch are ready to be included in the main history; merge it in. If not, keep them in the separate branch and continue rebasing.

    (side note: git merge --no-ff may be of use to create a merge-commit even if a fast-forward merge is possible -- depending on the rules of your project, this may be preferable)

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