简体   繁体   English

git:如何在创建分支之前获取master的最后一次提交

[英]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.

相关问题 Git:将最后一次提交从分支移动到主分支 - Git: move last commit from branch to master 最后一次提交拉到主分支 git - Last commit pull to master branch git 如何在 git 提交之前获取最后一个版本 - how to get the last version before a git commit 如何获取主分支的所有 Git 提交 hash ID - How to get all Git commit hash IDs of a master branch 如何在git中的master分支上首次提交之前移动后创建分支? - How to move later created branch before first commit on master branch in git? Git:如何从主分支中的较早/较旧提交创建新分支? - Git: How to create a new branch from an earlier/older commit in master branch? 推送到远程然后从远程主分支拉到本地后如何删除最后一个 git commit - How delete the last git commit after pushing to remote then pulling from remote master branch to local 如何将最后一个提交从一个分支复制到主分支 - How to copy the last commit from one branch to master branch 如何从提交树的底部创建一个新的 git 分支,它与 master 分支没有共同的提交? 对于 gh-pages - How can I create a new git branch from the base of the commit tree , which has no commit in common with master branch ? for gh-pages Git:如何撤消提交*和*恢复到最后一个分支 - Git: How to Undo commit *and* revert to last branch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM