SORU
23 HAZİRAN 2010, ÇARŞAMBA


Nasıl kolayca bir tamamlama geçmişi düzeltme yapabilir miyim?

Ben sadece amending a single file in a past commit in git ama, ne yazık ki "yeniden sıralar", istemiyorum. taahhüt edilen çözüm okuyun Burada benim sorum şu:

Her şimdi ve sonra, (alakasız) bir özellik üzerinde çalışırken benim kodunda bir hata fark ettim. Hızlı git blame sonra bir kaç hata yaparsa önce sunulmuş olduğunu ortaya koymaktadır (böcek piyasaya çok sana teslim ediyorum, en son bu yüzden genellikle commit). Bu noktada, ben genellikle bunu yapmak için:

git stash                      # temporarily put my work aside
git rebase -i <bad_commit>~1   # rebase one step before the bad commit
                               # mark broken commit for editing
vim <affected_sources>         # fix the bug
git add <affected_sources>     # stage fixes
git commit -C <bad_commit>     # commit fixes using same log message as before
git rebase --continue          # base all later changes onto this

Ancak, bu yukarıdaki sıra can sıkıcı oluyor o kadar sık olmuyor. 'İnteraktif rebase' sıkıcı. özellikle Bana rasgele bir geçmişte tamamlama değişiklikleri sahnelenen ile değiştirilmesine olanak veren yukarıdaki sıra, herhangi bir kısayol var mı? Bu tarihi değiştiren farkındayım, ama gerçekten bir şey gibi olmasını çok isterdim, bu yüzden sık sık hatalar yapıyorum

vim <affected_sources>             # fix bug
git add -p <affected_sources>      # Mark my 'fixup' hungs for staging
git fixup <bad_commit>             # amend the specified commit with staged changes,
                                   # rebase any successors of bad commit on rewritten 
                                   # commit.

Taahhüt veya tesisat araçları kullanarak yazabilirsiniz akıllı bir senaryo olabilir mi?

CEVAP
30 EYLÜL 2010, PERŞEMBE


GÜNCELLEME:Bir süre önce, --fixup yeni bir bağımsız değişken bir günlük mesaj git rebase --interactive --autosquash uygun taahhüt oluşturmak için kullanılabilir git commit eklendi. Yani commit artık bir son düzeltme için en kolay yolu:

$ git add ...                           # Stage a fix
$ git commit --fixup=a0b1c2d3           # Perform the commit to fix broken a0b1c2d3
$ git rebase -i --autosquash a0b1c2d3~1 # Now merge fixup commit into broken commit

Burada bir süre önce yazdım benim asıl sorum ben umut git fixup bu mantığı uygulayan küçük bir Python betiği. Komut bazı değişiklikler sahnelenen ve daha sonra verilen taahhüt bu değişiklikleri geçerli olduğunu varsayar.

NOTBu komut Windows özeldir; git.exe arar ve GIT_EDITOR ortam değişkeni set kullanarak ayarlar. Diğer işletim sistemleri için gerekli olarak ayarlayın.

Tam olarak uygulamak ben bu senaryoyu kullanarak 'kırık kaynakları düzeltme, düzeltmeler sahne, koş git' iş akışı için sordum: . düzelti

#!/usr/bin/env python
from subprocess import call
import sys

# Taken from http://stackoverflow.com/questions/377017/test-if-executable-exists-in python
def which(program):
    import os
    def is_exe(fpath):
        return os.path.exists(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None

if len(sys.argv) != 2:
    print "Usage: git fixup <commit>"
    sys.exit(1)

git = which("git.exe")
if not git:
    print "git-fixup: failed to locate git executable"
    sys.exit(2)

broken_commit = sys.argv[1]
if call([git, "rev-parse", "--verify", "--quiet", broken_commit]) != 0:
    print "git-fixup: %s is not a valid commit" % broken_commit
    sys.exit(3)

if call([git, "diff", "--staged", "--quiet"]) == 0:
    print "git-fixup: cannot fixup past commit; no fix staged."
    sys.exit(4)

if call([git, "diff", "--quiet"]) != 0:
    print "git-fixup: cannot fixup past commit; working directory must be clean."
    sys.exit(5)

call([git, "commit", "--fixup="   broken_commit])
call(["set", "GIT_EDITOR=true", "&&", git, "rebase", "-i", "--autosquash", broken_commit   "~1"], shell=True)

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • NextKsa

    NextKsa

    7 EKİM 2009
  • TeachMeComputer

    TeachMeCompu

    31 EKİM 2009
  • VOICE TV

    VOICE TV

    2 Aralık 2010