Git: renamed file manually, Git confused

前端 未结 5 1063
庸人自扰
庸人自扰 2020-12-23 09:21

I am using Git and manually renamed a file that I had added to the repository. Now, I have added the \"new\" file which I renamed to the repository but Git complains that th

5条回答
  •  我在风中等你
    2020-12-23 10:06

    This has to be automated. I never remember git until I commit, and I don't want to.

    #!/usr/bin/env python3
    
    # This `git rm` wrapper respects the `--cached` option (like `git rm`).
    
    import sys
    import subprocess
    
    if "--cached" in sys.argv:
        dest = sys.argv[-1]
        rest = sys.argv[1:-1]
        subprocess.check_call(["git", "add", dest])
        subprocess.check_call(["git", "rm"] + rest)
    else:
        subprocess.check_call(["git", "mv"] + sys.argv[1:])
    

    I don't want to "remember git mv", because git mv adds hidden state behind git diff that is implicitly added to the next commit, even if you explicitly commit something totally unrelated. I know, it's the so called "staged" state, but I don't like it. I like to commit without surprises.

提交回复
热议问题