使分支变基而无需签出 [英] Rebase a branch without checking it out

查看:114
本文介绍了使分支变基而无需签出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在一个有时构建时间较长的项目中进行构建,并且该构建经常被破坏.如果我有一个较旧的分支并正在进行一些工作(已提交,但基于一个较老的父级),则运行git checkout oldbranch会更改工作目录以表示所有旧代码,这使我需要运行完整版本再次.

So I'm working on a project that sometimes has long build times, and the build is clobbered very often. If I have an older branch with some work going on (which has been committed, but is based on an older parent), running git checkout oldbranch changes the working dir to represent all the old code, which makes me need to run a full build again.

但是,通常我只修改了一个或两个文件,其余的不需要重置.我想做的是将该分支重新设置为当前的主目录,并保留对文件的那些更改.

However, usually I've only modified one or two files, and the rest don't need to be reset. What I'd like to do is to rebase this branch to the current master head, and preserve those changes to the files.

基本上,如果a.rsb.rs已被修改,那么我需要一种使这些更改基于当前文件头的方式,而不触及除这两个文件以外的任何文件.

Basically, if a.rs and b.rs have been modified, then I need a way of making these changes base themselves onto the current head, without touching any files other than those two.

有没有做这种事情的方式?目前,我正在使用补丁文件来执行此操作.

Is there a git-ish way of doing this? Currently I'm juggling patch files to do this.

推荐答案

注意: 要直接解决问题中的确切问题,请寻找以下答案,这些答案更简单.

对于我想在不弄乱我的工作目录的情况下进行一些更改"这一更普遍的问题,请继续阅读.

如果您的回购订单很大,请参阅有关git worktree add的评论.

See the comments about git worktree add if your repo is very big.

克隆存储库,在克隆副本中建立基础,然后将其推回.

Clone the repo, make rebase in cloned copy, and push it back.

如果您位于回购中,则应为:

If you are inside your repo, it should be:

cd ..
git clone <name_of_your_repo_directory> tmp_repo
cd tmp_repo
git checkout origin/oldBranch
git rebase origin/master
git push -f origin HEAD:oldBranch

在tmp_repo中,origin是本地存储库的名称(当然是您克隆的存储库).

In tmp_repo origin is name of your local repo, of course (the one you cloned).

注意:效果会像这样

git checkout oldBranch
git rebase master

在您的原始存储库中,不是

in your original repo, not as

git checkout oldBranch
git rebase origin/master

这篇关于使分支变基而无需签出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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