假设我有一个本地Git仓库和一些未提交的更改。因为这些变化可能非常混乱,我还不想提交给我的分支机构,但我确实希望在云端进行测试。
我正在寻找一系列git命令,可以:
php -q "./yii.php" migrate/up --interactive=0 --migrationPath=@vendor/pheme/yii2-settings/migrations
mymessydev
。答案 0 :(得分:2)
让我们说你在主分支上遇到了混乱的变化,
git stash
git checkout -b messybranch
git stash apply
git add .
git commit -m "commit"
git push origin messybranch
git checkout master // clean master
此时,由于他们已经推送messybranch
,您不会失去这些更改。为了将这些更改恢复为master
,您可以合并messybranch
或者在master
上挑选提交
git merge messybranch
OR
git cherry-pick #commit
cherry-pick
或merge
会提交您的更改,但如果您希望他们上演但未提交,则可以
git reset head~1
答案 1 :(得分:1)
我编写了一个python脚本来自动执行此过程。它甚至适用于未跟踪的文件!
首先安装python绑定:pip install gitpython
import sys
from git import Repo
import time
def save(temp_branch, repo_path='.'):
repo = Repo(repo_path)
git = repo.git
work_branch = repo.active_branch.name
ret = git.stash()
is_stash = not 'No local changes' in ret
# delete the temp branch if already exist
try:
git.branch('-D', temp_branch)
except: # the branch doesn't exist, fine.
pass
git.checkout('-b', temp_branch)
if is_stash:
git.stash('apply')
git.add('.')
try:
git.commit('-m', 'temporary save ' + time.strftime('%m/%d/%Y %H:%M:%S'))
except:
print('no temporary changes to push')
git.push('-f', 'origin', temp_branch)
git.checkout(work_branch)
git.cherry_pick('-n', temp_branch)
print(git.reset('HEAD'))
save(*sys.argv[1:])