K.Mulier
K.Mulier

Reputation: 9620

Git: How to deactivate history for a specific subfolder?

1. Description of the problem

Suppose I have the following project foo:

Project foo is cloned from a GitHub repository I own, and checked out to the master branch. Subfolders bar and baz contain pure source code. Subfolder tools contains some software that I need to run the project.

From time to time, I delete software in the tools folder to replace them with newer versions. Git keeps the history of everything that ever existed in the tools folder. That is absolutely not necessary.

 

2. Questions

I've got two questions:

  1. Is it possible to delete the entire history of subfolder tools, without touching the history of bar and baz? The entire history of tools should be wiped out from my local .git repo and the remote GitHub repo once I push. When my coworkers pull, their local history of tools should be wiped out as well.

  2. Is it possible to - starting from today - make Git stop keeping history for the tools folder? For example: I replace tool_x_v1.0 with tool_x_v1.1, commit and push to GitHub. My coworkers pull from GitHub and should receive tool_x_v1.1. All traces of the old tool_x_v1.0 should be wiped out from the remote GitHub repo and all local .git repos.
    Note: We also assume that tool_x_v1.1 is perfectly backwards compatible with tool_x_v1.0.

 

3. Side effects

Now you may wonder:

What happens when I checkout an old commit - let's say a commit from 5 Nov 2018. The tools subfolder has no history dating back to that moment (its entire history is gone). What will it contain?

Subfolder tools should simply contain the current contents - no matter what old commit you're checking out. I would even go further: no matter what branch you're checking out. The tools folder has no history and is branch-agnostic. As simple as that.

 

4. Criticism

Some of you will think:

Just don't use Git for this tools subfolder (put it in .gitignore). Use something else to synchronize this particular subfolder with your coworkers.

That's indeed possible. But anyone who clones the git repo from GitHub will be unhappy when he/she realizes the project doesn't work. He/She will need to download the tools folder from some other source, and possible need to install some third-party software to keep it up-to-date. Very cumbersome, don't you think?

If you disagree - just ignore me and live happily ever after. Please don't go ranting in the comments, telling me how evil I am desecrating the noble Git.

Upvotes: 1

Views: 134

Answers (1)

alan ocallaghan
alan ocallaghan

Reputation: 3038

Question 1: yes. Use bfg or git filter-branch to remove just that subfolder, then add it to .gitignore. Note: this won't automatically remove other users' folders, thankfully, since in that case it would be possible to remove data from someone's repo using a pull request.

Question 2: You want git to record version changes without recording history? This isn't possible without a lot of push -f and reset --hard for all users. git lfs will stop git from keeping software versions as binary diffs, but can't handle this automatic updating without versioning you want. Perhaps a synced dropbox folder is closer what you're looking for.

Upvotes: 1

Related Questions