简体   繁体   English

Git提交然后签出与签出然后提交之间有区别吗?

[英]Is there a difference between Git commit then checkout and checkout then commit?

Suppose I am on a branch develop with changed files: 假设我正在使用更改的文件进行分支develop

Is there any difference (Git wise) if I do: 如果我这样做有什么区别(明智的选择):

$ git add *somefiles*
$ git commit
$ git checkout -b fix/new_branch
$ git push origin fix/new_branch

Instead of: 代替:

$ git checkout -b fix/new_branch
$ git add *somefiles*
$ git commit
$ git push origin fix/new_branch

Yes, in the first case your changes (which you add by git add *somefiles* ) will be there in both new and original branch while in later changes will just be in new branch. 是的,在第一种情况下,您的更改(通过git add *somefiles* )将同时存在于new和原始分支中,而在以后的更改中将仅存在于new分支中。

So if you want your changes to go to remote of new branch, you should chose the second option. 因此,如果您希望更改进入新分支的远程,则应选择第二个选项。

在这两种情况下, fix/new_branch的内容都是相同的,但是在第二个示例中, develop将不包含最近的更改,直到合并回去。

Git commit then checkout work like below git commit然后结帐工作如下

yes there is difference is that if we are using first commit at that time it will commit in local repository only. 是的,不同之处在于,如果我们当时使用的是第一次提交,则它将仅在本地存储库中提交。 after that we will take update at that time git will check when if server and local committed branch having same file changes at that time it will ask for merger 之后,我们将在那时进行更新git将检查服务器和本地提交的分支在同一文件时是否发生更改,它将要求合并

$ git add *somefiles* $ git commit $ git checkout -b fix/new_branch $ git push origin fix/new_branch

checkout then commit 签出然后提交

it will not check if merge is available or not in local respository. 它不会检查本地存储库中是否有合并功能。 it will force to commit your task 它将迫使您完成任务

always practice first one it is best 总是先练习最好

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

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