简体   繁体   English

提交然后签出git中的另一个分支进行旧提交?

[英]Commit then checkout another branch in git carries old commit?

If I am on branch b-one and I run git commit -m "init commit" and then git checkout -b b-two , does the commit carry to the new branch? 如果我在分支b-one并且运行git commit -m "init commit" ,然后运行git checkout -b b-two ,那么提交是否可以携带到新分支上? More generally, are commits branch specific? 更一般地说,提交分支是特定的吗? Or when you commit, are you just committing on your local machine and can access that commit from any branch? 或者,当您提交时,您是否只是在本地计算机上提交并且可以从任何分支访问该提交?

  1. Does the commit carry to the new branch? 提交是否携带到新分支? Yes, but only if it is a new branch. 是的,但前提是它是一个新分支。 Other existing branches will not have your commit in its history log. 其他现有分支机构的历史日志中将没有您的提交。

The git checkout command lets you navigate between the branches created by git branch. git checkout命令使您可以在git branch创建的分支之间导航。 Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch. 检出一个分支会更新工作目录中的文件,以匹配该分支中存储的版本,并告诉Git记录该分支上的所有新提交。 Think of it as a way to select which line of development you're working on. 可以将其视为选择您正在开发的开发路线的一种方式。

  1. More generally, are commits branch specific? 更一般地说,提交分支是特定的吗? No, history are shared. 不,历史是共享的。
  2. Or when you commit, are you just committing on your local machine ? 或者,当您提交时,您只是在本地计算机上提交? Yes, before pushed, no one else knows about your commit. 是的,在被推送之前,没有人知道您的提交。
  3. Can access that commit from any branch? 可以从任何分支访问该提交吗? No. What does 'access' mean ? 不。“访问”是什么意思? if you mean commit history or changed code, only branches created off a branch with your committed changes have your commit history. 如果您的意思是提交历史记录或更改的代码,则只有在具有已提交的更改的分支上创建的分支才具有提交历史记录。

It is more interesting when you switch branch with un-committed changes: Please read http://www.gitguys.com/topics/switching-branches-without-committing/ 当您切换具有未提交的更改的分支时,它会更有趣:请阅读http://www.gitguys.com/topics/switching-branches-without-committing/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM