git git_dir分支_Git –分支操作

git git_dir分支

git git_dir分支

Branches are new lines of the current development line. Branches creates new work spaces different from current and changes can be done without affecting current and other branches. After these changes generally branch will merge with the main branch.

分支是当前开发线的新线。 分支创建了不同于当前分支的新工作空间,并且可以在不影响当前分支和其他分支的情况下进行更改。 这些更改之后,通常分支将与主分支合并。

For example we want to add new feature. To code the new feature we create new branch and develop our code after being sure we can add this to our app we merge the branch with the main branch.

例如,我们要添加新功能。 为了对新功能进行编码,我们创建了新分支,并在确保可以将其添加到我们的应用程序后开发代码,然后将分支与主分支合并。

上市分行 (Listing Branches)

Listing branches can be done like below. This will show only local branches where branches resides in local. Remote branches exist in remote repositories.

列出分支可以像下面一样完成。 这将仅显示本地分支所在的本地分支。 远程分支存在于远程存储库中。

$ git branch  
* master

Listing remote branches can be done like below

列出远程分支可以像下面这样完成

$ git branch -a  
* master

Because we have no remote repository there is no remote branch and this command output is not different from previous.

因为我们没有远程存储库,所以没有远程分支,并且此命令输出与以前的命令没有什么不同。

More information about branches can be get with following command by adding -v .

可以通过添加-v使用以下命令获取有关分支的更多信息。

$ git branch -v 
* master 96511bc LICENSE,

As we see branches uid and last added file is show for detailed information.

我们看到分支uid和最后添加的文件显示了详细信息。

创建新分支 (Create New Branch)

We can create new branch easily like below. Created branch is local and will not pushed to the remote repository.

我们可以像下面这样轻松地创建新分支。 创建的分支是本地分支,不会推送到远程存储库。

$ git branch test 
$ git branch 
* master 
  test

As we see we create new branch with git branch test and list branches. Although we have created new branch we did not check the the branch test.

如我们所见,我们使用git branch test和list分支创建了新分支。 尽管我们创建了新分支,但并未检查分支测试

结帐处 (Checkout Branch)

To start with working test branch we need to checkout it. After the checkout the test branch master branch will not be the HEAD. HEAD is last commit of current work space.

要开始运行测试分支,我们需要将其检出。 签出后,测试分支主分支将不再是HEAD。 HEAD是当前工作空间的最后提交。

$ git checkout test 
Switched to branch 'test' 
$ git branch        
  master 
* test

We can create new branch and checkout with single command by providing -b argument.

通过提供-b参数,我们可以使用单个命令创建新分支和签出。

$ git checkout -b new-test                                                                                                            
Switched to a new branch 'new-test' 
$ git branch  
  master 
* new-test 
  test

重命名分支 (Rename Branch)

Renaming branch is easy as other operations.

与其他操作一样,重命名分支也很容易。

$ git branch -m new-test very-new-test 
$ git branch               
  master 
  test 
* very-new-test

删除分支 (Deleting Branch)

Branch can be completely deleted like below.

分支可以完全删除,如下所示。

$ git branch -d very-new-test 
Deleted branch very-new-test (was 96511bc). 
$ git branch        
  master 
* test

将更改推送到远程存储库 (Push Changes to the Remote Repository)

We can push a specific branch to the remote repository by specifying remote branch. If the remote branch is do not exists the branch is created at remote. If we do not specify remote repository by default origin is assumed.

我们可以通过指定远程分支将特定分支推送到远程存储库。 如果远程分支不存在,则在远程创建分支。 如果默认情况下我们未指定远程存储库,则假定来源。

$ git push origin test 
Counting objects: 3, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 267 bytes | 0 bytes/s, done. 
Total 3 (delta 1), reused 0 (delta 0) 
To /home/john/myproject/ 
   96511bc..eaa2efa  test -> test

分支之间的差异 (Diffing Between Branches)

Two branches can be diffed by using diff command.

可以使用diff命令来区分两个分支。

$ git diff master test 
diff --git a/thisistest b/thisistest 
new file mode 100644 
index 0000000..e69de29
LEARN MORE  How To Add New Repository To Apt In Linux?
了解更多如何在Linux中向Apt添加新存储库?

翻译自: https://www.poftut.com/git-branching-operations/

git git_dir分支

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值