您现在的位置是:主页 > news > 森马网站建设情况/今日热搜

森马网站建设情况/今日热搜

admin2025/5/30 14:56:33news

简介森马网站建设情况,今日热搜,wordpress中文用户名称,网站评估内容 优帮云Git每次提交的时候都会生成一个commit id,并且会按照时间排下来,这条线我们成为分支,仓库创建的时候,默认会有生成master分支,每次提交代码的时候,Git用master指向最新的提交,再用HEAD指向maste…

森马网站建设情况,今日热搜,wordpress中文用户名称,网站评估内容 优帮云Git每次提交的时候都会生成一个commit id,并且会按照时间排下来,这条线我们成为分支,仓库创建的时候,默认会有生成master分支,每次提交代码的时候,Git用master指向最新的提交,再用HEAD指向maste…

24d0ee00a5f3e88df3c6931186c4c69f.png

Git每次提交的时候都会生成一个commit id,并且会按照时间排下来,这条线我们成为分支,仓库创建的时候,默认会有生成master分支,每次提交代码的时候,Git用master指向最新的提交,再用HEAD指向master,就能确定当前分支。

448c4205aabe154b95be42f1634ab36d.png

当我们创建一个分支(test)的时候,git就是新建一个指针test,同master分支指向相同的commit id,同时HEAD指向test,如图所示:

68d2039a15801dfaaa072771d51dae07.png

下面我们进入实战

创建分支

Git创建分支很简单,执行 git branch <分支名>

git branch test

执行后,没返回信息,没消息就是最好的消息,我们执行git branch 查看下当前的分支

git branch
* mastertest

说明已经创建成功。

* 表示当前工作在那个分支上。

分支切换

如果我们想切换到test分支,怎么办? 用命令git checkout <分支名>

git checkout test
Switched to branch 'test'
git branchmaster
* test

分支合并

现在我们在test分支上继续修改readme.txt,添加test branch commit一行,提交到本地仓库,这个时候指针指向如下图:

4a2b6913d1b8b2fbdff115c42ce4d5b3.png

那我们如何将test分支上的这次提交合并到master上呢?git给我们提供一个命令来处理 git merge <分支名>。

首先我们需要将工作分支切换到mater,再执行 git merge test

git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
git merge test
Updating c785354..010129e
Fast-forwardreadme.txt | 1 +1 file changed, 1 insertion(+)

查看readme.txt发现test分支的修改test branch commit已经合并过来了。

cat readme.txt
Git is a distributed version control system
Git is free software
new commit
test branch commit

解决冲突

现在假如我们在两个分支上同时修改第一行的内容,再把test分支的修改合并到master会出现什么情况呢?来试下,

git merge test
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.

Git告诉我们,执行自动合并,但是自动合并失败了,同时告诉我们readme.txt文件发生了冲突。

cat readme.txt
<<<<<<< HEAD
Git is a distributed version control system master
=======
Git is a distributed version control system test
>>>>>>> test
Git is free software
new commit
test branch commit

其中<<<<<<< HEAD 到 ======= 中间的内容是当前工作分支(master分支)提交的内容。

======= 到 >>>>>>> test 是待合并分支(test分支)中的内容。手动处理如下:

cat readme.txt
Git is a distributed version control system master test
Git is free software
new commit
test branch commit

进行正常的git add,git commit 提交即可。

分支推到远程仓库

刚刚我们只是在本地新建了一个test分支,那么如何将test分支推到远程仓库呢?

git push <远程仓库名> <本地分支名>:<远程分支名>

git push origin test:test
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 533 bytes | 177.00 KiB/s, done.
Total 6 (delta 1), reused 0 (delta 0)
remote: Powered By 码云 Gitee — 开源中国 Git 代码托管平台
To 码云 Gitee — 开源中国 Git 代码托管平台:drag0n/gitlearning.git* [new branch]      test -> test

码云后台看下:

df65fe91b34d970ab2e0bc40e49b10ef.png

已经有两个分支了

删除本地分支

在实际开发过程中,频繁的要创建临时分支,用完后要删除,我们使用命令

git branch -D <分支名>,但要注意的是当前工作的分支不能是要删除的分支。(有点绕)

现在我们想要把test分支删除,先将工作分支切换的master,再执行删除命令:

git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
git branch -D test
Deleted branch test (was c785354).

删除远程分支

有时候我们也需要删除远程仓库上的分支,git push <远程仓库名> :<远程分支名>

注意:冒号前面的分支名不写,告诉远程仓库要删除掉该分支。

git push origin :test
remote: Powered By 码云 Gitee — 开源中国 Git 代码托管平台
To 码云 Gitee — 开源中国 Git 代码托管平台:drag0n/gitlearning.git- [deleted]         test