git 颜色扩展_GIT:扩展

git 颜色扩展

Nearly every VCS has some form of branching support. Branching means, you diverge from the main line of development and continue to do work without messing with that main line. In many VCS tools, this is a somewhat expensive process, often requiring you to create a new copy of your source code directory, which can take a long time for large projects.

几乎每个VCS都具有某种形式的分支支持。 Branching意味着,您脱离了开发的主线,并且继续进行工作而不会弄乱主线。 在许多VCS工具中,这是一个比较昂贵的过程,通常需要您创建源代码目录的新副本,这对于大型项目可能会花费很长时间。

Consider a tree for example. A tree always has some branches along with the large trunk. Similarly, branches in Git are smaller parts of the project which need not interfere with the main branch (recall master). They have their own commits and are added to master once they are completed. The master branch is like the trunk of a tree. In most cases, the code contained in the master branch is usually the one being deployed.

考虑一棵树。 一棵树总是与大树干一起有一些树枝。 同样,Git中的分支是项目的较小部分,不需要干扰主分支(调用主分支)。 它们具有自己的提交,并在完成后被添加到母版中。 主分支就像一棵树的树干。 在大多数情况下,master分支中包含的代码通常是正在部署的代码。

Some people refer to Git's branching model as its "killer feature", and it certainly lets Git apart in the VCS community. Why is it so special? Git branches are incredibly lightweight, making branching operations nearly instantaneous, and switching back and forth between branches generally just as fast. Unlike many other VCSs, Git encourages workflows that branch and merge often, even multiple times in a day. Understanding and mastering this feature gives you a powerful and unique tool and can entirely change the way that you develop.

有人将Git的分支模型称为其"killer feature" ,它肯定会使Git在VCS社区中脱颖而出。 为什么这么特别? Git分支非常轻巧,几乎可以立即进行分支操作,并且在分支之间来回切换的速度通常一样快。 与许多其他VCS不同,Git鼓励工作流经常分支和合并,甚至在一天内多次。 了解和掌握此功能可以为您提供强大而独特的工具,并且可以完全改变您的开发方式。

Let's consider that our awesome_project is based on a Web Development Project. You are currently on the master branch and it's going great, but you need to add a sign-in feature to your project. Now you certainly don't want this code to mess with your current code, do you? So let's give the feature its own branch. You create a new branch by using git branch command. Check the status of the repository to make sure you don't have anything to commit.

让我们考虑一下我们的awesome_project基于Web开发项目。 您目前位于master分支上,并且进展顺利,但是您需要在项目中添加登录功能。 现在您当然不希望此代码与您当前的代码混淆,是吗? 因此,让我们为功能提供自己的分支。 您可以使用git branch命令创建一个新分支。 检查存储库的状态,以确保您没有要提交的任何内容。

Name the new branch signin_feature: $ git branch signin_feature

将新分支命名$ git branch signin_feature signin_feature: $ git branch signin_feature

Check the status again. Hmm, we're still on the master branch. How do we switch to our new branch? Remember our friend from before, git checkout? This command can be used to switch between branches. When you don't provide it with a hash value, Git assumes that you want to switch to a branch. Go on and switch to the new branch we just created and check the status just to be sure.

再次检查状态。 嗯,我们仍在master分支上。 我们如何切换到新分支? 还记得我们以前的朋友, git checkout吗? 此命令可用于在分支之间切换。 当您不为其提供哈希值时,Git会假定您要切换到分支。 继续并切换到我们刚刚创建的新分支,并检查状态以确保。

$ git checkout signin_feature
Creating a Branch in Git

Go ahead and make a new file, file4 in this case and commit it. After you have successfully committed it, check the log. Certainly, you see the entry of the new commit sitting there.

继续创建一个新文件,在这种情况下为file4并提交。 成功提交后,请检查日志。 当然,您会看到坐在那里的新提交的条目。

Branching Out

Let's switch back to master and view the log again. Uh-oh. The commit is missing. Did we erase it? Don't worry the commit is still there. Git is smart enough to know that this commit was in the signin_feature branch and the master branch has nothing to do with it yet.

让我们切换回master并再次查看日志。 哦哦 提交丢失。 我们删除了吗? 不用担心提交仍然存在。 Git非常聪明,知道此提交位于signin_feature分支中,而master分支与此无关。

Branching out

Keep in mind that whenever you branch out, the new branch is a copy of the current branch you are on. As of now, we branched out from the master, hence all master commits were available in the log.

请记住,每当分支出去时,新分支就是您所在的当前分支的副本。 到目前为止,我们已经从主服务器分支出来,因此所有主服务器提交在日志中都可用。

There is another way you can create a new branch. Our friend, git checkout helps us bypass the branch command entirely. Go on and type the following at your command line. Let's create a new subscription feature:

还有另一种创建新分支的方法。 我们的朋友git checkout帮助我们完全绕过了分支命令。 继续,在命令行中键入以下内容。 让我们创建一个新的订阅功能:

$ git checkout -b subs_feature
Switching to a different branch in Git

The -b option lets you create a branch and switch to it all in one single command.

使用-b选项 ,您可以创建一个分支并在一个命令中将其全部切换到该分支。

Now that we've created some branches let's learn more about managing them. We have a total of 3 branches right now, but larger projects have hundreds or even thousands of branches. How do we keep track on which branches exist?

现在我们已经创建了一些分支,让我们进一步了解如何管理它们。 现在我们总共有3个分支,但是较大的项目有数百个甚至数千个分支。 我们如何跟踪存在的分支?

Git lets us view all the branches in the repository by using the 'git branch' command:

Git让我们使用'git branch'命令查看存储库中的所有分支:

$ git branch

This will give you a list of all branches along with your current branch. Let's say we decide to skip the subscription feature and delete it. Not every one of your ideas can get to the final project.

这将为您提供所有分支以及当前分支的列表。 假设我们决定跳过订阅功能并删除它。 并非您的每个想法都可以进入最终项目。

You can use the -D option in the branch command to delete your branch:

您可以在branch命令中使用-D选项删除您的分支:

$git branch -D subs_feature

Oops! We can't delete the branch we are currently working in. Switch back to master and try again.

糟糕! 我们无法删除当前正在使用的分支。切换回master,然后重试。

deleting a branch in Git

Phew! This was a long one. Good work. You deserve a cookie! Next up, we look into merging. What does that mean? Read on...

! 这是一个很长的时间。 辛苦了 你应该得到一个饼干! 接下来,我们考虑合并。 那是什么意思? 继续阅读...

翻译自: https://www.studytonight.com/github/branching-in-git

git 颜色扩展

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值