我使用git mv
重新命名了几个文件,使用了git stash
,快速查看了HEAD(没有更改),然后git stash pop
重新获得了整个批次。我的动作已经从提交列表中消失了,所以我用git rm
重新设置它们并且提交消息声称git发现重命名是重命名。所以我没想到它。
但是现在,提交后,我无法了解移动文件的历史记录!这就是git所说的有关提交的内容:
~/projects% git log --summary
commit de6e9fa2179ae17ec35a5c368d246f19da27f93a
Author: brone
Date: Wed Dec 8 22:37:54 2010 +0000
Moved R_DebugUI into runtime
delete mode 100644 test/R_DebugUI_iOS.h
delete mode 100644 test/R_DebugUI_iOS.m
create mode 100644 system/runtime/src/R_DebugUI_iOS.h
create mode 100644 system/runtime/src/R_DebugUI_iOS.m
<<snip older commits>>
~/projects%
我现在正试图获取其中一个移动文件的历史记录,所以我可以看一个旧版本,但我没有得到任何有用的东西:
~/projects/system/runtime/src% git log --follow --find-copies-harder -M -C R_DebugUI_iOS.m
commit de6e9fa2179ae17ec35a5c368d246f19da27f93a
Author: brone
Date: Wed Dec 8 22:37:54 2010 +0000
Moved R_DebugUI into runtime
~/projects/system/runtime/src%
(我也在没有-M
,-C
和--find-copies-harder
的情况下尝试过,但无济于事。)
我可以使用旧名称获取其历史记录,该名称在从旧位置删除时停止:
~/projects% git log --summary --follow --find-copies-harder -M -C -- test/R_DebugUI_iOS.m
commit de6e9fa2179ae17ec35a5c368d246f19da27f93a
Author: brone
Date: Wed Dec 8 22:37:54 2010 +0000
Moved R_DebugUI into runtime
delete mode 100644 test/R_DebugUI_iOS.m
commit 32a22d53c27e260714f759ecb3d3864e38b2e87f
Author: brone
Date: Tue Dec 7 23:52:51 2010 +0000
Can set debug UI's alpha.
<<snip older commits>>
~/projects%
所以这次我并没有完全陷入困境,但我不想一直这样做。 (我预计会有相当数量的文件在他们的生活中至少移动一次。)
我做错了吗?该文件的旧副本和新副本的相同值为98.8%(166个中的2行已更改)。我的理解是git应该能够在这种情况下跟踪文件,因为它推断重命名操作而不是显式存储它们,并且文件足够相似,我认为它应该认为它们是相同的。
我能做些什么来解决这个问题吗?
答案 0 :(得分:99)
请尝试在您的文件中使用git log --follow
。我从这里学习Is it possible to move/rename files in git and maintain their history?
答案 1 :(得分:25)
好吧,我确实看到我使用git log -M --summary
重新命名..
答案 2 :(得分:14)
回答我自己的问题,因为我已经设法缓解了我的担忧,即使我没有完全解决我的问题。 (git log --follow
但仍不适用于我。)
首先,重命名提交的--summary
日志包含文件旧名称的delete
行。因此,如果很容易发现,您可以从那里找到它的旧名称和git log
。
如果它是某个大型提交的一部分,因此有点难以发现 - 这种情况是我的担心之一 - git blame -C
可以与第一个重命名后修订版本上的文件新名称一起使用。据推测,原始文件中的行仍然存在! - 所以git应该找到它们的源代码,并显示旧的文件名(以及一个提交哈希以获得良好的衡量标准)。然后,您可以使用git log
获取路径。
因此,如果您对文件的历史感兴趣(无论出于何种原因),那么它似乎可以相对简单地完成。虽然我得到的印象是git更喜欢你正确使用它。
答案 3 :(得分:7)
public foo Dequeue(SqlConnection connection, SqlTransaction transaction)
{
using (var command = new SqlCommand(DEQUEUE_SPROC, connection) {CommandType = CommandType.StoredProcedure, Transaction = transaction})
{
var reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
ID = (Guid) reader["ID"];
Name = reader["Name"].ToString();
reader.Close();//Closing the reader
return this;
}
return null;
}
}
public string GetFilePathUri(SqlConnection connection, SqlTransaction transaction)
{
string filePathUri = "";
using (var command = new SqlCommand(FILEPATH_SPROC, connection) {CommandType = CommandType.StoredProcedure, Transaction = transaction})
{
var reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
filePathUri = reader["Path"].ToString();
}
reader.Close();//Closing the reader
}
return filePathUri;
}
我相信这就是你要找的东西。