2015-09-07 61 views
1

在交互式變形期間,我經常發現我想在當前變更集之前出現一些變化,例如,如果我有:如何git只存放上演檔案?

A->BCD->E 

我想要移動到:

A->D->BC->E 

所以我做了一個互動的底墊,並編輯相關的變更。所以,我希望能夠:

  1. reset --soft
  2. 提交BCD
  3. unstage d
  4. 藏匿階段性變化
  5. 承諾d
  6. 彈出藏匿
  7. 提交

這是p可能的,還是有一個更簡單的方法來實現這一目標?

回答

0

我問過關於官方git郵件列表的問題,但沒有得到真正的答案。 http://git.661346.n2.nabble.com/Proposal-for-git-stash-add-staged-option-td7629171.html

以下是我現在使用:

這使得它可以做到git cstash "optional message",將您所有的文件staged藏成藏。 它處理髒和乾淨狀態。

#/bin/sh 
# 
function evil_git_dirty { 
    [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "dirty" || echo "clean" 
} 

function create_stash { 
    # And convert into a stash 
    if [ "$1" == "" ] 
    then 
     # Unnamed stash 
     git stash 
    else 
     # Named stash 
     git stash save "$1" 
    fi 
} 

IS_DIRTY=$(evil_git_dirty) 

echo "$IS_DIRTY" 

if [ "$IS_DIRTY" == "clean" ] 
then 
    create_stash "$1" 
    exit 0 
fi 

# Put staged files in a tempory commit 
git commit -m 'temporary, will be stashed soon' --no-verify 
# Put everything else in a temporary stash 
git add . 
git stash 
# Remove commit 
git reset HEAD^1 

git add . 

create_stash "$1" 
# Pop the temporary stash 
git stash pop [email protected]{1} 
git reset . 
+0

我還沒有讀完整個腳本,但有兩件事情在我身上跳動。 1)儘管你的shebang指定了'sh',但你可以使用''[''''''''''''''''''''''''''''''''''''''' 2)'[-z「$ 1」]'比'[「$ 1」==「」]'更習慣。 – Jubobs