简体   繁体   English

如何推送由 Git 上的 pre-push 钩子修改的文件?

[英]How to push files modified by a pre-push hook on Git?

I have a Python script as a pre-push hook modyfing files inside my repo.我有一个 Python 脚本作为我的 repo 中的pre-push hook 修改文件。 Is there any possibility to immediately push those modified files as part of the same push?是否有可能将这些修改后的文件作为同一推送的一部分立即推送?

Here is the code:这是代码:

#!/usr/bin/env python

def sendUnpackedAsset():
    """Scan all .hdas available in the repo and unpack them."""

    hdas = os.listdir(
        f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/otls"
    )

    for count, hda in enumerate(hdas, start=1):
        if hda.endswith(".hda") or hda.endswith(".otl"):

            print(f">>> Unpacking {count} digital asset(s)...")

            unpackAsset(
                unpacked_dir_name=f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/otls/{os.path.splitext(hda)[0]}",
                source_hda_file=f"{os.path.dirname(os.path.dirname(os.path.dirname(__file__)))}/otls/{hda}",
            )

            if os.path.isfile(hda):
                print(f">>> Removing {count} digital asset(s)...")
                os.remove(hda)

It is modyfing binary files .hda or .otl contained in the repo, unpacking them to .txt files, and then removing the binary, leaving only the freshly created .txt files in the repo.它正在修改 repo 中包含的二进制文件.hda.otl ,将它们解压缩为.txt文件,然后删除二进制文件,只在 repo 中留下新创建的.txt文件。 Unfortunately, I need to push a second times to have those changes applied.不幸的是,我需要再推一次才能应用这些更改。

我认为您必须 git 添加任何修改过的文件并创建第二个提交,然后全部推送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM