简体   繁体   English

具有时间戳比较的版本控制系统

[英]Version Control System with timestamps comparison

I've been looking for a software like this for months, but couldn't find it. 我一直在寻找这样的软件已经好几个月了,但是找不到。 So, the situation is as following: 因此,情况如下:

  1. I have a folder with very old source code files. 我有一个包含非常旧的源代码文件的文件夹。 (My OS is Windows) (我的操作系统是Windows)
  2. Each file has it's creation date and modification date (2004-2006 years). 每个文件都有其创建日期和修改日期(2004-2006年)。
  3. This folder is at OneDrive server. 此文件夹位于OneDrive服务器上。

Now, the problem is that few months ago, because of some stupid reason, modification dates of some files were changed to the recent ones (2015 year). 现在,问题在于几个月前,由于某些愚蠢的原因,某些文件的修改日期更改为最近的文件(2015年)。 The content remained the same. 内容保持不变。 The problem is, that at this moment I have no idea regarding when exactly these files were last changed. 问题是,目前我不知道这些文件的最后更改时间。 And knowing this is important to me. 知道这一点对我很重要。 Ok, those are gone. 好的,那些都不见了。 The question is - how do I make sure the rest of files will not change their dates? 问题是-如何确保其余文件不会更改其日期? I am looking for a kind of version/revision control system, which will look not only for changes in content of file, but also for changes in it's attributes. 我正在寻找一种版本/修订控制系统,该系统不仅会查找文件内容的更改,还会查找其属性的更改。 And when I will suddenly notice the change of attributes, I will revert them. 当我突然注意到属性的更改时,我将还原它们。

I know that I can archive (backup) entire directory. 我知道我可以存档(备份)整个目录。 But that's not a comfortable option - unpacking each time I want to check file and adding each time some possible new files - will be boring. 但这不是一个舒适的选择-每次我要检查文件时都解压缩并每次添加一些可能的新文件时-都会很无聊。

I know that I can make a snapshots of directories (with ExamDiff Pro) each time I change/add something. 我知道每次更改/添加某些内容时,都可以使用ExamDiff Pro创建目录快照。 But that's also very time consuming and not handy. 但这也很耗时且不方便。 Also it will not allow me to see previous revisions of files. 另外,它也不允许我查看文件的先前版本。

So, in a nutshell: tool to preserve all previous versions of file (as much as possible, maybe with comments on who made change) taking into account file attributes: new creation date - means modified file; 因此,简而言之:考虑到文件属性,该工具用于保留文件的所有先前版本(尽可能多地添加注释,包括对更改者的注释):新创建日期-表示修改后的文件; hidden attribute - means modified file and so on. hidden属性-表示已修改的文件,依此类推。

I hope you, who read this, shall understand my situation. 希望阅读此书的您能理解我的情况。

Best regards, Yevhen 最好的问候,Yevhen

As suggested in the comments, since you are mostly interested about archiving older files, persisting their modification date, what you could do is use Git to keep track of the changes, and then for each file you backdate a commit that matches its modification date. 如评论中所建议,由于您最感兴趣的是归档较旧的文件,保留其修改日期,因此您可以使用Git跟踪更改,然后针对每个文件回溯与修改日期匹配的提交。 That way, even if Git will neither track file modification dates nor ensure that the file modification date when checking out matches the commit date, you have a way to persist the modification date and look it up later by checking the revision history. 这样,即使Git既不会跟踪文件修改日期,也不会确保签出时的文件修改日期与提交日期匹配,您仍然可以保留修改日期,并在以后通过查看修订历史记录来查找它。

So essentially, what you would need to do is find all files, sort them by modification date, and then for each file, create a commit with the file modification date as its commit date. 因此,从本质上讲,您需要做的是找到所有文件,按修改日期对它们进行排序,然后为每个文件创建一个以文件修改日期作为其提交日期的提交。

Once that is done, you just need some discipline for future changes that you remember to commit new changes as soon as possible so that their “modification date” is automatically tracked by the commit time. 一旦完成,您只需要为将来的更改做一些纪律,就记得尽快提交新更改,以便在提交时间自动跟踪其“修改日期”。


In order to create a backdated archive, you could use the following PowerShell script that I came up with quickly. 为了创建一个回溯的存档,您可以使用我快速想到的以下PowerShell脚本。 It does exactly what I explained above: It looks for all files recursively in a folder, sorts the files by modification date, and then for each file, it creates a new commit backdated to that file's modification date. 它完全按照我上面的解释进行操作:它以递归方式查找文件夹中的所有文件,按修改日期对文件进行排序,然后为每个文件创建一个追溯到该文件的修改日期的新提交。

Param([string] $Folder)
Write-Host 'Backdating files in folder' $Folder -ForegroundColor Green

Push-Location $Folder
git init
git commit --allow-empty -m 'Initialize repository'

Write-Host 'Looking for files: ' -NoNewLine -ForegroundColor Blue
$files = Get-ChildItem * -Recurse | ? { !$_.PSIsContainer } | sort LastWriteTime
Write-Host $files.Length -NoNewLine -ForegroundColor Yellow
Write-Host ' files found' -ForegroundColor Blue

Write-Host 'Committing files backdated to their last write time' -ForegroundColor Blue
$files | % {
    git add $_.FullName
    $date = $_.LastWriteTime.ToString('yyyy-MM-dd HH:mm:ss')
    $env:GIT_COMMITTER_DATE = $env:GIT_AUTHOR_DATE = $date
    git commit -m ('Backdating: ' + $date)
}

$env:GIT_COMMITTER_DATE = $env:GIT_AUTHOR_DATE = $null
Pop-Location
Write-Host 'Done.' -ForegroundColor Green

Just save that script into a file git-backdate.ps1 (you can also download it here ) and place it somewhere. 只需将该脚本保存到文件git-backdate.ps1 (也可以在此处下载 ),然后将其放置在某处。

Then, open a Windows PowerShell console, and then run the script and pass the directory you want to turn into an archived Git directory as the -Folder parameter. 然后,打开Windows PowerShell控制台,然后运行脚本,并将要转换为Git的目录作为-Folder参数-Folder

For example, I put the script onto my desktop, and have a folder gittest there as well. 例如,我将脚本放到桌面上,并在gittest也有一个文件夹gittest So I do the following: 因此,我执行以下操作:

cd ~\Desktop
.\git-backdate.ps1 -Folder .\gittest

Then, the script should automatically create a repository from it, and create commits for each file. 然后,脚本应自动从中创建一个存储库,并为每个文件创建提交。 You can cd into it and check with gitk to see a full history. 您可以对其进行cd检查,并使用gitk查看完整的历史记录。

Of course, you need to have Git for Windows installed in order to run this. 当然,您需要安装Windows版Git才能运行此程序。

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

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