我使用git作为本地源控制系统,主要用于历史和差异跟踪.我仍然希望使用rebase来对我将定期制作的WIP提交进行修复/压缩.当我尝试做的时候git rebase -i,我得到以下内容:
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-rebase(1) for details
git rebase <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> MyBranch
Run Code Online (Sandbox Code Playgroud)
看来git不希望你在没有上游遥控器的情况下使用交互式rebase?我怎么做?
给定以下分支结构:
*------*---*
Master \
*---*--*------*
A \
*-----*-----*
B (HEAD)
Run Code Online (Sandbox Code Playgroud)
如果我想合并我的B更改(并且只有我的B更改,没有A更改)到master,这两组命令之间有什么区别?
>(B) git rebase master
>(B) git checkout master
>(master) git merge B
Run Code Online (Sandbox Code Playgroud)
>(B) git rebase --onto master A B
>(B) git checkout master
>(master) git merge B
Run Code Online (Sandbox Code Playgroud)
如果我使用第一种方式,我主要感兴趣的是如果来自分支A的代码可以使它成为主.
我的本地树与主人分道扬:
$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 7 and 3 different commit(s) each, respectively.
#
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)
我试过git pull --rebase并且失败了:
$ git pull --rebase
First, rewinding head to replay your work on top of it...
Applying: * ...
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging ChangeLog
CONFLICT (content): Merge conflict in ChangeLog
Failed …Run Code Online (Sandbox Code Playgroud) 我的git仓库中有一个开发分支和一个功能分支.我添加了一个开发提交,现在我想将该提交合并到我的功能分支.如果我这样做
git checkout feature
git merge develop
Run Code Online (Sandbox Code Playgroud)
我最终得到了合并提交.由于我将频繁地将关于开发的新提交合并到我的功能分支,所以我想避免所有这些不必要的合并提交.我看到这个答案建议做一个git rebase develop但是它最终会重新绕过我的分支方式而且rebase失败了.
更新: 我最终做的是
git checkout feature
git merge develop # this creates a merge commit that I don't want
git rebase # this gets rid of the merge commit but keeps the commits from develop that I do want
git push
Run Code Online (Sandbox Code Playgroud)
更新:我刚刚注意到,当我合并然后rebase到功能分支时,开发时的原始提交会获得不同的哈希.我不认为这就是我想要的,因为最终我会将功能合并到开发中,我猜这不会很好.
我不明白之间的差别git pull --rebase,并git rebase没有任何其他选择.
我不明白他们是安全的,良好的做法,还是非常危险的.
我可以git pull --rebase在当地做一个破坏历史的承诺吗?
这是我经常遇到的常见工作流障碍:
$ git status
# On branch master
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)
$ git checkout -b foo
$ echo "hello" > world
$ git add .
$ git commit -m "init commit for foo module"
$ git checkout master
$ git merge foo
Run Code Online (Sandbox Code Playgroud)
在接下来的几周内,将有更多代码直接由其他分支机构提交.foo分支将在这段时间内不受影响
$ git checkout foo
Run Code Online (Sandbox Code Playgroud)
不好了!foo已经过时了!我理解为什么,但我确实需要foo重新同步.
如何从foo分支机构获取最新内容?
假设我只是衍合分支foo上master,有冲突的.我想foo通过引入额外的更改或丢失更改(除了适合冲突解决的更改),确保我不会在冲突解决期间意外损坏内容.我这样做是通过:
diff -u <(git diff `git merge-base master foo@{1}` foo@{1}) \
<(git diff `git merge-base master foo ` foo )
Run Code Online (Sandbox Code Playgroud)
(更新:或我刚刚提醒的等效...语法git-diff:)
diff -u <(git diff master...foo@{1}) <(git diff master...foo) | mate
Run Code Online (Sandbox Code Playgroud)
这向我展示了master..foo被认为是补丁的所有变化,这正是我想要检查的最小化.但是,调用很复杂,输出的解释并不完全简单.
有没有更好的方法来完成这项任务 - 提供相同的信息,但有更好的方法或格式 - 或者我应该采取上述内容并将其包装在脚本中?
我正在尝试在git存储库中压缩一些提交.
> git rebase -i HEAD~3
Successfully rebased and updated refs/heads/staging.
文件打开标题为git-rebase-todo:
pick a2f3467 Require statement incorrect
pick c41212e Require file in environment
pick 2743221 This should work
# Rebase c5f42f3..2743221 onto c5f42f3
# ..........
Run Code Online (Sandbox Code Playgroud)
我尝试将底部的两个提交更改squash为pick.我保存文件,我收到以下错误:
Unable to save ~/Documents/code/myapp/.git/rebase-emrge/git-rebase-todo
当我git rebase -i在与同事共享的分支上执行操作时,我经常想要自己修改自己的提交.但是,因为交互式rebase工具不会将作者信息添加到rebasing文件(所有t给出的是提交哈希和描述),所以我最终必须检查另一个选项卡中的提交以查看它们是否是我的.
有没有办法给git rebase -i一个--format旗帜(或类似的东西),让它包括作者?
我做了git rebase很多提交我做了很长时间.我不小心--skipped提交了一些我解决过的冲突.我应该做的git rebase --continue.
是否有办法在此rebase阶段重新应用此先前的提交,然后继续rebase?
我看到的一种方式是
或者我可以在一个篮板阶段做一个樱桃挑选?
git ×10
git-rebase ×10
branch ×1
git-branch ×1
git-diff ×1
git-merge ×1
git-pull ×1
rebase ×1
sublimetext2 ×1
workflow ×1