Git 命令执行拉取并将我的更改放在顶部而不隐藏?
Git command to do a pull and put my changes at the top without stashing?
每次我必须从存储库中获取最新的更改时,我必须存储我的更改,然后进行拉取,然后再次取消存储我的更改,当有很多人在这个项目上工作时,这个过程会变得非常乏味,而你每天必须这样做很多次。
我想知道是否有 git 命令可以做到这一点。
您可以编写 shell 别名或 git 命令别名来执行此操作。
[alias]
update = !git stash save -u && git pull && git stash pop
我把 -u
放在那里以存储未跟踪的文件,以防拉动添加它们。
我不知道这样的命令(也许其他人知道...编辑:很棒的推荐 Schwern!)
但是,您是在功能分支上工作吗?如果没有,我强烈建议将它们添加到项目的 git 工作流程中。这将减少您需要更新本地分支机构的次数,因为理论上每个分支机构的人数会更少。
我发现这个 git 工作流程参考在过去很有用:http://nvie.com/posts/a-successful-git-branching-model/
运行 git pull --rebase
可能就是你想要的。
-r
--rebase[=false|true|preserve]
When true
, rebase the current branch on top of the upstream branch after fetching. If there is a remote-tracking branch corresponding to the upstream branch and the upstream branch was rebased since last fetched, the rebase uses that information to avoid rebasing non-local changes.
When set to preserve
, rebase with the --preserve-merges
option passed to git rebase
so that locally created merge commits will not be flattened.
When false
, merge the current branch into the upstream branch.
See pull.rebase
, branch.<name>.rebase
and branch.autoSetupRebase
in git-config if you want to make git pull
always use --rebase
instead of merging.
您提到您正在该分支中与其他开发人员一起工作,因此请注意文档该部分末尾的警告。
Note
This is a potentially dangerous mode of operation. It rewrites history, which does not bode well when you published that history already. Do not use this option unless you have read git-rebase carefully.
您正在寻找 git-up,它完全符合您的要求(以及更多)。
它执行以下操作:
- 获取所有本地分支
- 重新设置(而不是合并)所有具有关联远程分支的本地分支中的任何传入更改
- 本地更改是 stashed/unstashed before/after rebase
我经常使用它,它非常适合保持回购同步,而无需手动检查分支、存储、弹出等。
您使用
安装它
gem install git-up
然后您可以在任何 Git 存储库中使用它
git up
就这些了...
做一个正常的 git fetch
然后 git rebase --autostash
怎么样?
来自 man git-rebase
:
--[no-]autostash
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.
每次我必须从存储库中获取最新的更改时,我必须存储我的更改,然后进行拉取,然后再次取消存储我的更改,当有很多人在这个项目上工作时,这个过程会变得非常乏味,而你每天必须这样做很多次。
我想知道是否有 git 命令可以做到这一点。
您可以编写 shell 别名或 git 命令别名来执行此操作。
[alias]
update = !git stash save -u && git pull && git stash pop
我把 -u
放在那里以存储未跟踪的文件,以防拉动添加它们。
我不知道这样的命令(也许其他人知道...编辑:很棒的推荐 Schwern!)
但是,您是在功能分支上工作吗?如果没有,我强烈建议将它们添加到项目的 git 工作流程中。这将减少您需要更新本地分支机构的次数,因为理论上每个分支机构的人数会更少。
我发现这个 git 工作流程参考在过去很有用:http://nvie.com/posts/a-successful-git-branching-model/
运行 git pull --rebase
可能就是你想要的。
-r
--rebase[=false|true|preserve]
When
true
, rebase the current branch on top of the upstream branch after fetching. If there is a remote-tracking branch corresponding to the upstream branch and the upstream branch was rebased since last fetched, the rebase uses that information to avoid rebasing non-local changes.When set to
preserve
, rebase with the--preserve-merges
option passed togit rebase
so that locally created merge commits will not be flattened.When
false
, merge the current branch into the upstream branch.See
pull.rebase
,branch.<name>.rebase
andbranch.autoSetupRebase
in git-config if you want to makegit pull
always use--rebase
instead of merging.
您提到您正在该分支中与其他开发人员一起工作,因此请注意文档该部分末尾的警告。
Note
This is a potentially dangerous mode of operation. It rewrites history, which does not bode well when you published that history already. Do not use this option unless you have read git-rebase carefully.
您正在寻找 git-up,它完全符合您的要求(以及更多)。
它执行以下操作:
- 获取所有本地分支
- 重新设置(而不是合并)所有具有关联远程分支的本地分支中的任何传入更改
- 本地更改是 stashed/unstashed before/after rebase
我经常使用它,它非常适合保持回购同步,而无需手动检查分支、存储、弹出等。
您使用
安装它gem install git-up
然后您可以在任何 Git 存储库中使用它
git up
就这些了...
做一个正常的 git fetch
然后 git rebase --autostash
怎么样?
来自 man git-rebase
:
--[no-]autostash
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.