- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在玩 git 并在这里感到困惑。
develop
的HEAD分行位于
235a6d8
当我这样做时:
git checkout 235a6d8
来自任何其他分支机构 或来自 develop
分支,这让我保持独立的头脑。
我不确定为什么在我检查该分支上的最新提交时会发生这种情况。
当我这样做时:
git checkout develop
我可以正确切换到 develop 分支。
我没有得到 git checkout <commit-has>
之间的区别 和 git checkout branchname
.
它们有何不同?
最佳答案
A git checkout <commit-hash>
,准备在<commit>
之上工作,通过分离它的 HEAD(参见“DETACHED HEAD" section”),并更新工作树中的索引和文件。
虽然 git checkout <branch>
进行切换:它准备处理 <branch>
,通过更新索引和工作树中的文件,并将 HEAD 指向分支来切换到它。
这令人困惑。
Mark Longair在“Why is the git command to switch branches named “ git checkout
”?”中记录了这种混淆
他还在 2012 年 5 月写道:“The most confusing git terminology”:
In CVS and Subversion “checkout” creates a new local copy of the source code that is linked to that repository.
The closest command in Git is “git clone
”.
However, in git, “git checkout
” is used for something completely distinct.
In fact, it has two largely distinct modes of operation:
- To switch HEAD to point to a new branch or commit, in the usage git checkout
<branch>
. If<branch>
is genuinely a local branch, this will switch to that branch (i.e. HEAD will point to the ref name) or if it otherwise resolves to a commit will detach HEAD and point it directly to the commit’s object name.- To replace a file or multiple files in the working copy and the index with their content from a particular commit or the index.
This is seen in the usages:git checkout -- (update from the index)
andgit checkout <tree-ish> --
(where<tree-ish>
is typically a commit).In my ideal world, these two modes of operation would have different verbs, and neither of them would be “
checkout
”.
嗯...这就是为什么 Git 2.23(2019 年第 3 季度)会将 checkout 拆分为:
git restore
更新工作树(可能还有索引)git switch
它可以切换分支,或者根据要求分离一个分支,以便将所有新提交添加到该分支的顶端。关于git checkout <commit-hash> 与 git checkout 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57123031/
我正在寻找一种方法来编写 Signed-off-by:当我提交时自动标记。 我尝试通过 .git/config 文件配置它 (Reference) .我把这些代码行: [alias] comm
我使用的是 visual studio 2013,在提交 C# 代码时我面临 3 个选项。我需要解释每个选项之间关于我的本地存储库与 GitHub 存储库发生的情况的差异。 选项 1 表示提交 选项
我刚从 classes12.jar 升级到新的 jdbc 驱动程序到 ojdbc7.jar 我的应用在使用 ojdbc7.jar 运行时抛出异常: java.sql.SQLException: Cou
我问的是 Oracle SQL*PLUS ... 最佳答案 没有 :-) Oracle says The WORK keyword is supported for compliance with s
我必须在许多分支、许多存储库上恢复对文件所做的更改。我知道我可以使用 git checkout 哈希文件名,然后推送该更改。 问题是,我只知道在我想要恢复的实际提交之前有两次提交。 我怎样才能在这之前
看起来很简单,但我就是不明白。我在我的应用程序的根目录中。 这是我的工作流程。 git add . git commit -m "added a new feature some files chan
假设我有一个 git 分支,在共享它之前的最后审查中,我发现了一些小错误,例如拼写错误。我想做的是将那个补丁应用为“修复”,但它实际上会影响许多提交,因此在最终历史记录中没有错误的迹象。 也就是说,如
当我运行hg commit时,Mercurial会为我的提交消息生成一个文件,如下所示: HG: Enter commit message. Lines beginning with 'HG:' a
我已经为项目创建了一个新的存储库,并向其中添加了一些现有的代码库 (llvm)。该代码库大约有 18,000 个文件,这使得我的初始提交花费了大量时间。 (阅读5小时) 有没有办法将这个巨大的提交分成
我在 git review 上得到以下内容: git review You are about to submit multiple commits. This is expected if you
我一直在寻找一种替代解决方案来压缩分支中的一系列提交。我过去所做的是使用 git rebase -i HEAD~然后选择哪个 promise 进行压缩。通常我 pick编辑最新的提交,并压缩其间的冗余
把玩Git和GitHub,我发现有时候一个 git commit -a 需要提交修改过的文件。 (此文件已添加到项目中)。 但有时候,只是一个 git commit 会起作用。如果使用 Mercuri
我正在努力思考 Git 的复杂性。 我使用“git clone [url here]”从 GitHub 下载了一个存储库。 我做了一些更改,尝试使用“git commit”提交它们。这似乎没有将更改推
当试图恢复到之前的提交时,我尝试了: git revert --no-commit 0766c053..HEAD 然而这给出了一个错误: empty commit set passed 问题错误是什么
我的存储库的历史非常复杂。我经常发现自己想知道过去的某个提交是“在”还是“可从”某个修订版(通常是我的一个头脑)“进入”或“可访问” 我该怎么做呢? 最佳答案 您可以使用 revsets syntax
我有:http://windows.github.com/ 我当前的项目有大约 20k 个文件,大约 150MB(并且不说它有多慢而且我现在什么也做不了)它甚至不允许我提交!我收到此错误:提交失败:无
我正在运行 postgres 9.2 服务器并有一个使用 psycopg 2.5 的 python 客户端。 我进行了一些测试,因为我在日志文件中遇到了很多警告:没有正在进行的事务条目。 我有一些代码
我的主要问题是总是执行 git commit -am 而不是 git add 是否有意义。然后是 git commit -m? 我知道 -am 表示它将添加修改后的 TRACKED 文件的所有更改。所
如果我想查看 之间的差异和工作目录 (WD),我运行 % git diff 这通常会做我想做的事,但如果 WD 包含在 时被跟踪的文件,它就会这样做。已创建,但现在(或在当前分支中)未被跟踪,则
我正在阅读有关 git 对象的信息:blob、树、提交、标签。为了更好地理解 git 的工作原理,我尝试了一些低级命令,如 write-tree 和 commit-tree。 mkdir 测试; cd
我是一名优秀的程序员,十分优秀!