[英]git: How to get the last commit of master before a branch create
I want to see the difference between a branch and the master immediately before the branch was created, to see all changes made to the branch. 我想查看分支与创建分支之前的主节点之间的区别,以查看对该分支所做的所有更改。
I get my latest branch in a working directory (dirA/): 我在工作目录(dirA /)中得到了最新的分支:
cd /home/me/dirA/
git clone <my remote repo>
git checkout my_branch
I want to then get the master just before I created my_branch: cd /home/me/dirB/ git clone How do I checkout the master commit immediately before I did my git branch my_branch before I changed my_branch ? 我想在创建my_branch之前获得主服务器:cd / home / me / dirB / git clone如何在更改my_branch之前在执行git分支my_branch之前立即检出master提交?
I want to see the difference between a branch and the master immediately before the branch was created, to see all changes made to the branch.
我想查看分支与创建分支之前的主节点之间的区别,以查看对该分支所做的所有更改。
The ...
operator can show all changes done in a branch compared to a base branch: 与基础分支相比,
...
运算符可以显示分支中完成的所有更改:
git diff origin/master...
(It's not a typo that there is nothing after the ...
. This is equivalent to git diff origin/master...HEAD
, just shorter to type.) (在
...
之后没有任何错是不是错字。这等效于git diff origin/master...HEAD
,只是键入要短一些。)
You've (probably inadvertently) asked two questions. 您(可能无意中)问了两个问题。
What you're trying to accomplish 您要完成的工作
I want to see the difference between a branch and the master immediately before the branch was created, to see all changes made to the branch.
我想查看分支与创建分支之前的主节点之间的区别,以查看对该分支所做的所有更改。
is something for which git diff
has special notation. 是
git diff
具有特殊表示法的东西。
git diff master...my_branch
Note that ...
is used somewhat differently by different commands. 请注意,
...
在不同的命令中使用的方式有所不同。 But for diff
it does exactly what you want. 但是对于
diff
它确实可以满足您的需求。 (In particular, two dots does something different in the case of diff
, which - if you're used to using ..
with log
, might be confusing.) (特别是,在
diff
的情况下,两个点的作用有所不同-如果您习惯将..
与log
一起使用,可能会造成混淆。)
And while that's probably the information you really need, what you actually asked was 虽然这可能是您真正需要的信息,但您实际上要问的是
How do I checkout the master commit immediately before I did my
git branch my_branch
before I changed my_branch ?在更改my_branch之前,如何在执行
git branch my_branch
之前立即检出master提交?
To locate the commit you'd use 找到您要使用的提交
git merge-base master my_branch
In a bash shell, you could therefore say 因此,在bash shell中,您可以说
git checkout `git merge-base master my_branch`
From your question, it seems you plan to check out each branch in a different clone. 从您的问题来看,您似乎计划检出不同克隆中的每个分支。 The only apparent advantage this has over using the
git diff
command above would be that both trees are on your file system, so if for some reason a tool you want to use for the comparison won't play nice with git, still you could use it. 与上面的
git diff
命令相比,它唯一的明显优势是两棵树都在文件系统上,因此,如果由于某种原因要用于比较的工具不能与git配合使用,您仍然可以使用它。
Actually you could do that even without a second clone by using git worktree
to check out a second working tree on a single repo; 实际上,即使没有第二个克隆,您也可以通过使用
git worktree
在单个git worktree
上签出第二个工作树来做到这一点。 but that only really matters if either (1) there's substantial overhead to cloning (maybe because of dependency on an LFS store?), or (2) you plan to keep both working trees around and don't want to have to manage two databases / two sets of refs 但这仅在以下情况下才真正重要:(1)克隆的开销很大(也许是由于对LFS存储的依赖?),或者(2)您计划保留两棵工作树并且不想管理两个数据库/两套裁判
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.