简体   繁体   English

在读取文件时使用git签出另一个提交

[英]Checking out to another commit with git while reading the file

I am creating a server that handles version control of files in server and let the client view them at specific commit if they wanted. 我正在创建一个处理服务器中文件版本控制的服务器,如果需要的话,让客户端在特定提交时查看它们。

The way I implement this is that when user clicks a specific commit, I call checkout [hash of commit] to revert the file back to what it was and then read from that file. 我实现此方法的方式是,当用户单击特定的提交时,我调用checkout [hash of commit]将文件还原回原来的状态,然后从该文件读取。

The problem is that two people may be trying to read different commits of the same repository at the same time, meaning the state of file may change while reading from the file. 问题是两个人可能试图同时读取同一存储库的不同提交,这意味着从文件中读取文件时文件的状态可能会更改。

I tried checking out another commit while reading from it and it seems to work okay but I cannot be sure when the it is scaled. 我尝试从中读取另一个提交,但似乎可以正常工作,但是我不确定何时缩放它。

I am using nodeJS and express for my server. 我正在使用nodeJS并为我的服务器express When nodeJS starts reading file, will it still be the same state as the point when it started reading or would it change along with the change that is forced by git if I checkout another commit while reading the file? 当nodeJS开始读取文件时,它是否仍与开始读取时的状态相同,或者如果我在读取文件时签出另一个提交,它是否会随着git强制的更改而改变?

Instead of using checkout, consider show : 不要使用checkout,而是考虑show

git show <commit id>:<filename>

This will print the contents of the file at that commit. 这将在提交时打印文件的内容。 If you absolutely need it in a file, generate a unique temporary filename and redirect the output: 如果绝对需要一个文件,请生成一个唯一的临时文件名并重定向输出:

git show <commit id>:<filename> > tmpfile_uniquesuffix

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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