简体   繁体   中英

Is it possible to store the history of some files separately in Git?

There is a repository with code.

I want to store some directories and files in the repository, but so that their changes are not reflected in the development history.

For example, there is a catalog .vscode with VS Code settings and a file with notes my_notes.txt , and I want to be able to access them from different computers.

How can I make sure that the specified directories and files are saved in the repository (preferably with the history of changes), but so that their history is not mixed with the history of code development and at the same time they are available in this repository?

For example, I changed the my_notes.txt on one computer and then made a commit:

git commit my_notes.txt <some_magic>
git push <some_magic>

After that I want to get this file on another computer:

git pull <some_magic>

Perhaps orphaned branches are suitable for this, but I could not find how to do so I want.

If I do so:

echo my_notes.txt >> .gitignore
git add .gitignore
git commit -m 'update gitignore'
git checkout --orphan orhf-branch
git rm -r --cached .
rm -rf *
echo 'some text' > my_notes.txt
git add .
git commit -m 'Orphan commit'
git checkout master

then file my_notes.txt disappears from the master branch.

Is it possible to make the file my_notes.txt was present when I switch to the master branch, but the history of its changes was saved in the orhf-branch ? And so that I can change it in the master branch, but it doesn't show up as changed or untracked in master ?

You could add the branch orhf-branch of your own repository as a submodule in your master branch.

For an example of such a technique, see " What's the easiest way to deploy a folder to a branch in git? ".

As a submodule, my_notes.txt would be visible in a subfolder (say ' orhf ') which is the root folder of the submodule.
Yet, any change/new commit made in the master branch would be separate from the orhf_branch .

Any changes you are making in the orhf_branch and pushing, can be updated in any clone with a git submodule update --remote .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM