Zum Beispiel, ich habe eine Datei t.json, der Inhalt ist Zweig in Master fusionieren:wie durch PyGithub
{
"a": "abcdefg"
}
Und Datei t.json gedrückt zu meistern Zweig. Dann füge ich einige Inhalte der Datei und Kasse zu einem neuen Zweig, so dass die Datei wie folgt aussieht jetzt:
{
"a": "abcdefg",
"b": "mkjuujj"
}
Jetzt kann ich zwei Commits vergleichen PyGithub verwenden. Codes sind wie folgt aus:
WORKING_BRANCH = "my_new_branch"
new_branch_ref_str = "refs/heads/%s" % WORKING_BRANCH
branch_ref = None
all_ref = repo.get_git_refs()
for ref in all_ref:
if ref.ref == new_branch_ref_str:
branch_ref = ref
break
if not branch_ref:
# create branch from this commit
b = repo.get_branch("master")
branch_ref = repo.create_git_ref(ref=new_branch_ref_str,
sha=b.commit.sha)
last_head = repo.get_branch(WORKING_BRANCH)
fc = repo.get_file_contents("/t.json", ref=WORKING_BRANCH)
file = 't.json'
commit_message = "create a new branch with changes"
input_file = open(file, 'rb')
data = input_file.read()
result = repo.update_file("/t.json",
commit_message,
data,
fc.sha, branch=WORKING_BRANCH)
diff_url = repo.compare(last_head.commit.sha,
result['commit'].sha)
print diff_url.diff_url
das ist, was ich habe:
diff --git a/t.json b/t.json
index ef03bf5..b775e51 100644
--- a/t.json
+++ b/t.json
@@ -1,3 +1,4 @@
{
- "a": "abcdefg"
+ "a": "abcdefg",
+ "b": "mkjuujj"
}
Was soll ich tun my_new_branch in Master-Zweig fusionieren von PyGithub verwenden. Vielen Dank. Schätze es wirklich.