自动提交存储库中的更改

2024-04-26 20:59:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我们正在尝试自动提交对旧目录的更改,在那里人们不想使用版本控制(sight)之类的东西。在

我每天晚上都在使用gitpython提交这些更改:

repo = git.Repo(local_directory)

changed_files = [change.a_blob.path for change in repo.index.diff(None)]
if changed_files or repo.untracked_files:

   if changed_files:
      repo.git.add(update=True)

   if repo.untracked_files:
      repo.git.add(repo.untracked_files)

   repo.git.commit(message='Auto committed')
   repo.remotes.origin.push(repo.head)

有时提交失败,并返回“git commit--message=Auto committed”,退出代码为1—我无法重现

我做错什么了吗?我读过也许我应该用回购指数做出承诺?在

最好的, 克里斯托弗


Tags: git目录addmessageautoifrepofiles
1条回答
网友
1楼 · 发布于 2024-04-26 20:59:29

你是绝对正确的你需要使用回购指数做出承诺。下面是我的脚本中使用GitPython的一个工作示例(它顺便帮助我们进行版本控制)

repo = Repo(repo_dir)
index = repo.index

然后是我的提交版本函数:

^{pr2}$

所以你可以把“Auto-committed”作为你的commit_msg传入。希望这有帮助!在

相关问题 更多 >