在子目录工作中如何查看old_branch *?

发布于 2025-02-11 15:29:58 字数 482 浏览 1 评论 0原文

我是Git的新手,最近对下面的代码感到困惑。我的问题是,

  • 为什么git branch new_branch将复制当前Release_branch
  • 结帐新分支后,为什么我们可以输入子目录,然后重新检查一个旧分支以带上旧脚本?
  • 为什么最后一个结帐行(对于旧分支)只能恢复此子目录中的文件,而不是将所有脚本或切换到旧分支?
# Say pwd is /home/ab/
git checkout -f $RELEASE_BRANCH
git branch $NEW_REPAIR_BRANCH
git checkout $NEW_REPAIR_BRANCH
cd /home/ab/cd/ef/
rm -r *
git checkout $OLD_REPAIR_BRANCH *

有人可以帮助我解释逻辑吗?非常感谢!顺便说一句,我相信他们也应该能够简化!

I am new to git and recently get confused about the code below. My question are,

  • Why git branch new_branch will copy the current release_branch?
  • After checkout the new branch, why we could enter a sub directory and just re-checkout an old branch to bring in the old script?
  • Why the last checkout line (for old branch) will only restore the files in this subdirectory instead of bringing all scripts or switching to the old branch?
# Say pwd is /home/ab/
git checkout -f $RELEASE_BRANCH
git branch $NEW_REPAIR_BRANCH
git checkout $NEW_REPAIR_BRANCH
cd /home/ab/cd/ef/
rm -r *
git checkout $OLD_REPAIR_BRANCH *

Is there anyone could help me explain the logic? Much appreciate! Btw, I believe they should be able to be simplified as well!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年已逝 2025-02-18 15:29:58

为什么git branch new_branch会复制当前rapery_branch?

git branch new_branch git branch new_branch head是简短的。它从当前头创建new_branch。如果head指向Release_branch,则相当于git branch new_branch Release_branch

结帐新分支后,为什么我们可以输入子目录和
只需重新检查一个旧分支以带来旧脚本?

为什么最后一个结帐行(对于旧分支)只会还原
此子目录中的文件,而不是带上所有脚本或
切换到旧分支?

git Checkout $ old_repair_branch意思是“结帐$ old_repair_branch”。但是git Checkout $ old_repair_branch *完全不同。它根本不会切换分支。 *是指当前文件夹下的所有文件和目录。名称以点开头的文件和目录被排除在外,例如.git.gitignore

# enter /home/ab/cd/ef
cd /home/ab/cd/ef/

# remove all files and directories under /home/ab/cd/ef/
# files like `.gitignore` and folders like `.git` are not removed
rm -r *

git Checkout $ old_repair_branch *old_repair_branch中更新了其版本的文件。想象一下,它创建了一个文件,其内容记录在old_repair_branch中。由于*仅引用当前目录下的条目,因此其父目录和兄弟姐妹目录中的文件不受影响。

Why git branch new_branch will copy the current release_branch?

git branch new_branch is short for git branch new_branch HEAD. It creates new_branch from the current HEAD. If HEAD points to release_branch, then it's equivalent to git branch new_branch release_branch.

After checkout the new branch, why we could enter a sub directory and
just re-checkout an old branch to bring in the old script?

Why the last checkout line (for old branch) will only restore the
files in this subdirectory instead of bringing all scripts or
switching to the old branch?

git checkout $OLD_REPAIR_BRANCH means "to checkout $OLD_REPAIR_BRANCH". But git checkout $OLD_REPAIR_BRANCH * is quite different. It does not switch the branch at all. * means all files and directories under the current folder. The files and directories whose names start with a dot are excluded, like .git and .gitignore.

# enter /home/ab/cd/ef
cd /home/ab/cd/ef/

# remove all files and directories under /home/ab/cd/ef/
# files like `.gitignore` and folders like `.git` are not removed
rm -r *

git checkout $OLD_REPAIR_BRANCH * updates the files with their versions in OLD_REPAIR_BRANCH. Imagine that it creates a file with its content recorded in OLD_REPAIR_BRANCH. As * refers to the entries under the current directory only, the files in its parent directories and sibling directories are not affected.

神回复 2025-02-18 15:29:58

可以使用git> git switch command command command command command commit( a href =“ https://git-scm.com/docs/git-switch” rel =“ nofollow noreferrer”> man page ),以及 git Restore (用于基于文件的操作: Man Page )。

git switch -c $NEW_REPAIR_BRANCH $RELEASE_BRANCH
git restore --source $OLD_REPAIR_BRANCH

这样,您清楚地将分支开关与文件还原步骤区分开。
并且您避免'*',这取决于要解释和扩展的基础外壳。

Anything done with git checkout/git branch could be done with the new git switch command (man page), as well as git restore (for file-based operations: man page).

git switch -c $NEW_REPAIR_BRANCH $RELEASE_BRANCH
git restore --source $OLD_REPAIR_BRANCH

That way, you clearly distinguish the branch switches from the files restore steps.
And you avoid '*', which depends on the underlying shell to be interpreted and expanded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文