fabian
fabian

Reputation: 1839

Git Version Control separately for files in repository

I would like to track version of various files in a folder separately instead of tracking the entire repository.

To be more concrete, I initialized a folder as git repository. This folder contains multiple files. As changes in one file do not necessarily affect the others but they all belong to one "project" I would like to keep track of the files separately. In particular, I would like to commit files separately, and have separate logs for each file. Checking out an earlier version of one specific history should not affect the entire repository but only one specific file.

I know that I could solve my problem but creating a dedicated repository for each file but I dislike this idea for aesthetic reasons. Is there any other way to track files the way I outline above?

Upvotes: 0

Views: 895

Answers (2)

spume
spume

Reputation: 2004

Many git commands have variants for individual files

git log -- individual_file
git show commit_hash:individual_file
git checkout commit_hash -- individual_file

That 2nd command can also be piped to a text editor.

Upvotes: 1

Burhan Khalid
Burhan Khalid

Reputation: 174624

git only tracks files, not directories. You can have many files under a directory, but only one or two are actually tracked.

To do this, simply add those files to git.

Since git tracks each file, each file has its own individual history. You can always check what exactly was done to each file in a git repository; simply provide the file name to git log, as in git log somefile.txt

You can also checkout a specific file given you know the commit hash for it.

git is a very powerful "platform" (I refuse to call it a tool, because its so much more than that); almost any exotic workflow or requirement is doable - it may not be recommended but git will give you enough rope to hang yourself.

However, what you have asked is just normal day-to-day operations in git. I would only caution against the "single file checkout" requirement.

This requirement is better served by having one repository, and a branch for each file you want to work on separately. Checking out a branch will cause your file system to "hide" all the other files and only give the ones you are concerned with.

Upvotes: 2

Related Questions