git add 增加修改过的文件脚本

 

如果修改过的文件比较多,逐个git add比较麻烦,于是写了个脚本,把所有修改过的文件都添加

#!/usr/bin/env python3
import os

def main():
    files = os.popen("git status | grep modified:").readlines()
    for item in files:
        file = item.split("modified:",1)[1].strip().replace(" ","").replace("\n","").replace("\r","").replace("\t","")
        print(file)
        os.system("git add "+file)
    os.system("git status")

if __name__ == '__main__':
    main()

 

下面这个将再提交之前,执行代码格式化,然后自动将代码提交到branch

#!/usr/bin/env python3
import os

def main():
    os.system("~/astyl.sh")
    files = os.popen("git status | grep modified:").readlines()
    for item in files:
        file = item.split("modified:",1)[1].strip().replace(" ","").replace("\n","").replace("\r","").replace("\t","")
        print(file)
        os.system("git add "+file)
    os.system("git status")
    if len(files): 
        submit_info = input("input submit info:")
        if (os.system("git commit -m \""+submit_info+"\"")==0):
            branch_info = input("input submit branch:")
            if (os.system("git push origin "+branch_info) != 0):
                print("git push origin " + branch_info + "fail")
        else:
            print("git commit fail")
    else:
        print("no modified files to submit")
    

if __name__ == '__main__':
    main()

 

你可能感兴趣的:(python,工具)