可以“拉扯”自动存储和弹出挂起更改? [英] Can "git pull" automatically stash and pop pending changes?

查看:215
本文介绍了可以“拉扯”自动存储和弹出挂起更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何解决这个问题:

  user @ host $ git pull 
正在更新9386059..6e3ffde
错误:对以下文件的本地更改将被合并覆盖:
foo.bar
请在提交更改或隐藏它们之前进行合并。
正在取消

但是没有办法让 git拉为我跳舞隐藏 pop 跳舞?



如果此命令的名称不同,则表示正确。



创建shell别名> git stash; git pull; git stash pop 是一个解决方案,但我寻找更好的解决方案。 解决方案

对于Git 2.6+(2015年9月28日发布)



唯一的

<$ p> $ p> rebase.autoStash




设置为true,在操作开始之前自动创建一个临时存储器,并在操作结束后应用它。

这意味着您可以在脏工作树上运行重新绑定。然而,谨慎使用:成功重新绑定后的最终隐藏应用程序可能会导致不小的冲突。


结合:

  pull.rebase 




如果为true,抓取分支的顶部,而不是在运行git pull时合并默认分支的默认分支。



  git config pull.rebase true 
git config rebase.autoStash true

简单的 git pull 就足够了即使在一棵肮脏的树上也能工作。

在这种情况下不需要别名。




参见 commit 53c76dc (2015年7月4日)作者: Kevin Daudt( Ikke
(由 Junio C Hamano - gitster - commit e69b408 ,2015年8月17日)


:当 rebase.autostash 启用时允许脏树



rebase学会存储变化,当它遇到一个脏的工作树,
,但 git pull --rebase 不会。



只验证工作当 rebase.autostash 不是
时,树很脏。







注意:如果您想要在没有自动存储的情况下拉动(即使设置了 rebase.autoStash true ),你已经从git 2.9(2016年6月):

  pull --rebase --no-autostash 

请参阅提交450dd1d 提交1662297 commit 44a59ff 提交5c82bcd commit 6ddc97c commit eff960b 提交efa195d (2016年4月2日)和 commit f66398e 提交c48d73b (2016年3月21日)作者: Mehul Jain( mehul2029

(由 Junio C Hamano合并 - - gitster - 提交7c137bb ,2016年4月13日)



提交f66398e 尤其包括:


pull --rebase :add - [no-] autostash flag



如果设置了 rebase.autoStash 配置变量,
将无法覆盖它从命令行输入 git pull --rebase



示教 git pull --rebase - [no-] autostash 命令行标志
覆盖<$ c $的当前值c> rebase.autoStash ,如果设置。作为 git rebase
理解 - [no-] autostash 选项,这只是一个问题在调用 git pull --rebase >时将
选项传递给底层的 git rebase






警告:在Git 2.14(2017年第3季度)之前, git pull --rebase --autostash 当本地历史快速转发到上游时并没有自动隐藏。

请参见提交f15e7cf (2017年6月1日) .com / tylerbrazierrel =noreferrer> Tyler Brazier( tylerbrazier )。
(由 Junio C Hamano - gitster - 位于 commit 35898ea ,2017年6月5日)


pull :ff - rebase --autostash 可以在脏回购中使用



当一个脏存储库中的 git pull --rebase --autostash 导致
快进时,正在被自动解压缩并且拉出失败。

这是由于当我们可以快进时,避免运行rebase的快捷方式,
但在该代码路径上忽略autostash。



I know how to solve this:

user@host$ git pull
Updating 9386059..6e3ffde
error: Your local changes to the following files would be overwritten by merge:
    foo.bar
Please, commit your changes or stash them before you can merge.
Aborting

But isn't there a way to let git pull do the stash and pop dance for me?

If this command has a different name, it's ok.

Creating a shell alias for git stash; git pull; git stash pop is a solution, but I search for a better solution.

解决方案

For Git 2.6+ (released 28 Sept 2015)

The only git config setting which would be of interest is:

rebase.autoStash

When set to true, automatically create a temporary stash before the operation begins, and apply it after the operation ends.
This means that you can run rebase on a dirty worktree.

However, use with care: the final stash application after a successful rebase might result in non-trivial conflicts. Defaults to false.

combine that with:

pull.rebase

When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run.

git config pull.rebase true
git config rebase.autoStash true

That would be enough for a simple git pull to work even in a dirty tree.
No alias needed in that case.


See commit 53c76dc (04 Jul 2015) by Kevin Daudt (Ikke).
(Merged by Junio C Hamano -- gitster -- in commit e69b408, 17 Aug 2015)

pull: allow dirty tree when rebase.autostash enabled

rebase learned to stash changes when it encounters a dirty work tree, but git pull --rebase does not.

Only verify if the working tree is dirty when rebase.autostash is not enabled.


Note: if you want to pull without autostash (even though rebase.autoStash true is set), you have since git 2.9 (June 2016):

 pull --rebase --no-autostash

See commit 450dd1d, commit 1662297, commit 44a59ff, commit 5c82bcd, commit 6ddc97c, commit eff960b, commit efa195d (02 Apr 2016), and commit f66398e, commit c48d73b (21 Mar 2016) by Mehul Jain (mehul2029).
(Merged by Junio C Hamano -- gitster -- in commit 7c137bb, 13 Apr 2016)

Commit f66398e in particular includes:

pull --rebase: add --[no-]autostash flag

If rebase.autoStash configuration variable is set, there is no way to override it for "git pull --rebase" from the command line.

Teach "git pull --rebase" the --[no-]autostash command line flag which overrides the current value of rebase.autoStash, if set. As "git rebase" understands the --[no-]autostash option, it's just a matter of passing the option to underlying "git rebase" when "git pull --rebase" is called.


Warning: before Git 2.14 (Q3 2017), "git pull --rebase --autostash" didn't auto-stash when the local history fast-forwards to the upstream.

See commit f15e7cf (01 Jun 2017) by Tyler Brazier (tylerbrazier).
(Merged by Junio C Hamano -- gitster -- in commit 35898ea, 05 Jun 2017)

pull: ff --rebase --autostash works in dirty repo

When git pull --rebase --autostash in a dirty repository resulted in a fast-forward, nothing was being autostashed and the pull failed.
This was due to a shortcut to avoid running rebase when we can fast-forward, but autostash is ignored on that codepath.

这篇关于可以“拉扯”自动存储和弹出挂起更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆