擅长:python、mysql、java
<p>Git status说它被删除是因为工作副本中不存在该文件,这就是为什么签出它可以修复状态。在</p>
<p>看起来在德威还没有对高级工作拷贝类和函数的支持。你必须处理树和斑点,并解包对象。在</p>
<p>好吧,接受挑战:我可以和德威进行基本结账:</p>
<pre><code>#get repository object of current directory
repo = Repo('.')
#get tree corresponding to the head commit
tree_id = repo["HEAD"].tree
#iterate over tree content, giving path and blob sha.
for entry in repo.object_store.iter_tree_contents(tree_id):
path = entry.in_path(repo.path).path
dulwich.file.ensure_dir_exists(os.path.split(path)[0])
with open(path, 'wb') as file:
#write blob's content to file
file.write(repo[entry.sha].as_raw_string())
</code></pre>
<p>它不会删除必须删除的文件,也不会关心索引等。<br/>
另请参见<a href="https://github.com/mikofski/dulwichPorcelain" rel="nofollow">Mark Mikofski's github project</a>,以获取基于此的更完整的代码。在</p>