Reputation: 3684
It seems that it is not easy possible to commit a file which a different content but with the same date/time.
Thw following situation:
How can I force the commit!?
Here is a repro code with libGit2Sharp:
using System.IO;
using LibGit2Sharp;
using System;
namespace GitWorkingUpdateProblem01
{
class Program
{
static void Main(string[] args)
{
const string repoDir = @".\git-Test";
Repository.Init(repoDir);
using (var repo = new Repository(repoDir))
{
string fileName = Path.Combine(repo.Info.WorkingDirectory, "foo.bar");
var dt = new DateTime(2015, 01, 01, 00, 00, 00);
using (var sw = new StreamWriter(fileName, false))
{
sw.WriteLine("UNIQUE-TEXT-1234");
}
File.SetLastWriteTime(fileName, dt); File.SetCreationTime(fileName, dt);
repo.Stage(fileName); repo.Commit("1");
using (var sw = new StreamWriter(fileName, false))
{
sw.WriteLine("UNIQUE-TEXT-4321");
}
File.SetLastWriteTime(fileName, dt); File.SetCreationTime(fileName, dt);
repo.Stage(fileName); repo.Commit("2"); // ==> THROWS: No changes; nothing to commit.
}
}
}
}
Upvotes: 3
Views: 350
Reputation: 27357
I could reproduce it even without libgit2sharp
(using TortoiseGit & msysgit).
It's a known issue:
https://github.com/msysgit/git/issues/312
https://groups.google.com/forum/#!topic/git-users/Uo9TDppHTSI
I was able to get it to detect changes by running:
git read-tree HEAD
in the console. If your library allows you to run this (or arbitrary) commands - it may help out as well.
In any case, this is something that deliberately fights against git, so I would advise against manually changing the ModifiedDate
if possible.
Upvotes: 2