开发者

Can git track files but not show them as updated?

开发者 https://www.devze.com 2023-03-03 22:18 出处:网络
Use case: we have some project meta-data files which we want tracked, but are rarely (if ever) committed, though they are locally updated all the time (different users have different project paths). I

Use case: we have some project meta-data files which we want tracked, but are rarely (if ever) committed, though they are locally updated all the time (different users have different project paths). In regular scenarios, no user should ever commit these files unless explicitly required.

Git ignore is used for untracked files.

Is there a similar function for git to ignore tracked files? Is there a s开发者_JS百科aid method that I can change in the central repo, and will reflect on all users?


Is there a said method that I can change in the central repo, and will reflect on all users?

No in a general (distributed) context: no hook or process of any kind can be "changed" on a central location and picked by all distributed downstream repos.

If your user created their repo following a central template, then some default hook could reference a central script (i.e. a script accessible by all users in a shared disk, if we are speaking on users on the same network).


adymitruk's answer argues to use a development branch, hence not committing private changes to "public" branch (i.e. branch that is pushed/pulled).
That is well and good but:

  • this isn't an automatic process (enforceable to all repos), but an action taken by each developer individually (or not taken because they forgot)
  • this involves sorting out the commits you don't want to publish from the ones you need to publish, which you would do in any case with a development branch, except in this case the developer has to do the extra step of remembering that any changes to those particular files must not be merged to the public branch. Ever. (provided he/she actually took the time to isolate those particular changes in a separate commit!)

It would be better to use a filter driver (which is declared in a .gitattributes file and can be propagated through clone) with:

Can git track files but not show them as updated?

  • a smudge script:

    • able to recognize the content of your meta-data files
    • saving their content on a checkout
  • a clean script:

    • able to recognize the content of your meta-data files
    • decide if their modifications need to be committed or not
    • restore the initial content of those meta-data files on commit


$ git update-index --assume-unchanged <filename>

This only works locally, though.


Use development branches. Commit your specific change for your environment. Back merge with ours strategy. Now those changes will never be shared to the public branch. The other answers are missing the point of using development branches.

0

精彩评论

暂无评论...
验证码 换一张
取 消