あるブランチのツリーの状態を覚えておいて、この特定のブランチに対して隠していたものだけを復元するのに相当するgit stash && git checkout $branch && git stash pop
を使用することもできます。どのように簡単に達成することができますか?デザインによってブランチを保存し、隠しを保存しますか?
答えて
、git stash
は一時的に上の任意の分岐ではありませんをコミットします。これはあなたがどこにでもそれを適用することができるようにです。
インデックスやワークツリーの状態を保存し、その状態を特定のブランチに関連付ける場合は、Gitが提供するものはgit commit
です。本当に、それはあなたが必要とするすべてです:普通の古いコミット。 git reset --soft HEAD^
を使用して、そのブランチに戻ってくると、後で「コミットしない」ことができます。
これを1つのパッケージにまとめたい場合は、「本当の」コミットで使用しないことを約束した短いコミットメッセージを選択し、git checkout
の小さなラッパーを書くことができます(これは全くテストされていません) :
#! /bin/sh
# git-swapto: commit any temporary work, swap to another branch;
# automatically de-commits temporary work.
# for git-sh-setup: can work in subdirectory
SUBDIRECTORY_OK=true
. $(git --exec-path)/git-sh-setup
case $# in
1) ;;
*) die "usage: git-swapto <branch>";;
esac
require_work_tree
# From require_clean_work_tree, converted to status;
# assumes work tree exists.
work_tree_is_clean() {
git update-index -q --ignore-submodules --refresh
# if diff-files says different, fail (work tree not clean)
git diff-files --quiet --ignore-submodules || return 1
# if diff-index says index is different, fail (index not clean)
git diff-index --cached --quiet --ignore-submodules HEAD || return 1
# both work tree and index are clean => nothing to commit
return 0
}
# Force branch name as argument, since we want to do a soft
# reset if there is a temporary commit on it. Also, require
# that current HEAD name a branch.
case "$(git rev-parse --symbolic-full-name "$1")" in
refs/heads/*) ;;
*) die "`$1': not a branch name";;
esac
git symbolic-ref -q HEAD >/dev/null || die "not currently on a branch"
temp_commit_string="!! temporary commit, do not push"
# test whether HEAD refers to our temporary commit
current_commit_is_temp() {
local head_text="$(git log --no-walk --pretty=format:%B)"
test "$head_text" = "$temp_commit_string"
}
# Before leaving this branch, make a temporary commit if
# necessary, amending existing temporary commit if there is one.
# (We should never need --amend, this is just paranoia.)
if ! work_tree_is_clean; then
echo "note: leaving temp commit behind" 1>&2
if current_commit_is_temp; then
git commit -a --amend --no-edit ||
die "cannot update current temp commit"
else
git commit -a -m "$temp_commit_string" --no-edit ||
die "cannot make temp commit"
fi
fi
# work tree is now clean, switch to target
git checkout "$1" || die "cannot switch to $1"
# finally, if it is our special temp commit, reset it away
if current_commit_is_temp; then
git reset --soft HEAD^ || die "failed to unmake temp commit"
fi
# all done, for good or ill...
実際には、少なくとも2、そして時には3、一時的なコミットを行います。しかし、これは "ポリシー"よりも "メカニズム"ですが、 "ブランチにはない"はポリシー/デザインです。
それとも、あなたは別に「インデックス」と「仕事・ツリー」を保持したい場合はgit stash
と同様に、コミットを使用します。さもなければ、いつものようにインデックスに物を追加してから、1回コミットしてください。
stash-and-checkout
コマンドをgit-whistlesとすることもできます。 Git-whistlesはRubyの宝石ですので、Rubyがインストールされている場合は、gem install git-whistles
でgit-whistlesをインストールできます。次に、あなたがしたいことを達成するために単にgit stash-and-checkout [branch]
を行うことができます。
は、簡潔にするために、私はとても新しいブランチにコミットされていない現在のブランチ上での作業、スイッチを隠しておくと、(もしあれば)そのブランチのスタッシュをポップするために、stash-and-checkout
のためのgitのためのシェルのエイリアスg
、およびgitのエイリアスco
を定義しました単にg co [branch]
と入力するだけです。 gitエイリアス設定の例については、.gitconfig(github.com/vwal/my-git-extras)を参照してください。
- 1. アンドロイドアプリにデータを保存して隠す
- 2. データを保存しないカスタムポストメタを保存します
- 3. 保存隠しとパスワードEXCELシート
- 4. PHPはリモートサーバにファイルを保存/保存しますか?
- 5. 保存した情報を保存
- 6. editTextを保存します
- 7. EditResume()を保存します。
- 8. シンプルドッカープロジェクト/ JPEGを保存して保存 - ボリュームを使用しますか?
- 9. Rails - has_manyを使ってリレーションを保存し、親を保存せずに保存しました
- 10. gitは最後にチェックアウトしたブランチをどこに保存しますか?
- 11. Microsoft Wordで保存したドキュメントのパスを保存しますか?
- 12. numpy.ndarrayをイメージとして保存し、ピクセル値を保存します。
- 13. ループバック保存イベントを「保存前」操作でキャンセルします
- 14. '保存後のコンテキスト'を保存します
- 15. コアデータ保存エラー(NSValidationErrorKey、Cocoaエラー1570)NSDateを保存します
- 16. プライベートgitリポジトリにブランチを保存する
- 17. gitブランチでスナップショットを保存する
- 18. Firefoxはパスワードを保存しますが、ログインフォームのパスワードを保存しません。
- 19. ggplot2オブジェクトをggplotlyとして保存し、Linuxのディスクに保存します
- 20. gitはローカルリポジトリの隠しファイルをどこに保存しますか?
- 21. Visual Studioでは、隠しデータをコンパイル済みファイルに保存しますか?
- 22. PHP:ファイルをWindows、Linux(MacOS?)で隠しファイルとして保存
- 23. スタックを保存しますか?
- 24. データをcoredataに保存しますか?
- 25. GCMをデータベースに保存しますか?
- 26. コアデータをコアデータに保存しますか?
- 27. ファイルをURLから保存します。
- 28. TabControlにデータを保存しますか?
- 29. Mongooseはasyncを保存しますか?
- 30. TextViewからSharedPreferencesを保存します