2
代碼非常簡單,它只是打開Windows命令提示符並執行calling()函數。它有基本的git命令,可以幫助我推送到git倉庫。我配置了ssh和遠程回購。Python Git Bash CMD腳本
鏈接:https://github.com/vivekpatani/git-script-gitter
我可以更改日期,但是當我把它與git,它會顯示在我推開,而不是一個我所犯下的當前日期。
提交列表中顯示位置承諾7天前和11天前,我希望它實際上顯示爲犯了同樣的日期。
def calling():
#Simply opening command prompt in Windows
subprocess.call("git --version")
subprocess.call("git status")
subprocess.call("git add .")
subprocess.call("git commit -am \"Changing Things\" --date=\"Sat, 26 Mar 2016 18:46:44 -0800\"")
subprocess.call("git push origin master")
#To stop from cmd closing automatically
temp = input("Enter to close:")
def main():
calling()
if __name__ == "__main__":
main()
環顧四周後,我看到我需要將AUTHOR DATE和COMMIT DATE一起更改?有人可以幫我解決問題嗎?編輯1: 我正在使用Windows操作系統。
它在我通過Git Bash運行時起作用,不知何故只需將它轉換爲Python即可。
git --version
git status
git add .
GIT_AUTHOR_DATE='Fri Mar 25 19:32:10 2016 -0800' GIT_COMMITTER_DATE='Fri Mar 25 19:32:10 2016 -0800' git commit -am "Hello Laney"
git push origin master
編輯2:解決方案
def calling(git_date):
subprocess.call("git --version")
subprocess.call("git status")
subprocess.call("git add .")
#The next statement is important as updates/adds new GitCommiterDate in environment making it the current commit date.
os.environ["GIT_COMMITTER_DATE"] = 'Fri Mar 25 19:32:10 2016 -0800'
#The date in commit command only changes author date.
subprocess.call("git commit -am \"Changing Things\" --date=\"Fri Mar 25 19:32:10 2016 -0800\"")
subprocess.call("git push origin master")
謝謝,但是當我打印os.environ,我找不到GIT_COMMITTER_DATE。此行還包含語法問題。請你能指導我嗎? –
@VivekPatani的目標是*將該變量添加到環境變量中,而不是找到它。 – VonC
@VivekPatani此外,缺少一個雙引號。 – VonC