Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Git Bash CMD脚本_Python_Windows_Git_Bash_Github - Fatal编程技术网

Python Git Bash CMD脚本

Python Git Bash CMD脚本,python,windows,git,bash,github,Python,Windows,Git,Bash,Github,代码非常简单,只需打开windows命令提示符并执行calling()函数。它有基本的git命令,可以帮助我推送到git repo。我已经配置了ssh和远程repo 链接: 我可以更改日期,但当我将其推送到git时,它会显示我推送的当前日期,而不是我提交的日期 def calling(): #Simply opening command prompt in Windows subprocess.call("git --version") subprocess.call(

代码非常简单,只需打开windows命令提示符并执行calling()函数。它有基本的git命令,可以帮助我推送到git repo。我已经配置了ssh和远程repo

链接:

我可以更改日期,但当我将其推送到git时,它会显示我推送的当前日期,而不是我提交的日期

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()
提交列表显示9天前和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()
环顾四周后,我读到我需要同时更改作者日期和提交日期?谁能帮帮我吗

编辑1: 我在Windows操作系统上工作

当我通过GitBash运行它时,它就工作了,不知何故只需要将它转换为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")
--date
仅修改作者日期

您需要设置
GIT\u COMMITTER\u DATE
环境变量,以使日期与作者日期(、和)相同


谢谢,但是当我打印os.environ时,我找不到GIT_提交人的日期。该行还包含语法问题。请你指导我好吗?@VivekPatani目标是将该变量添加到环境变量中,而不是找到它。@VivekPatani还缺少一个双引号。我只是对你所说的做了一些修改。您提到的答案是正确的,但由于它仍然存在问题,我只是将命令分为两部分。os.environ[“GIT\u提交人\u日期”]=“Fri,2016年3月25日18:46:44-0800”,然后是subprocess.call(“GIT提交-上午\“改变事物\”-日期=“Fri,2016年3月25日18:46:44-0800\”)@VivekPatani太棒了!请毫不犹豫地编辑此答案。