git merge 详细操作,看完就懂
Posted mashuai 的博客(base成都)
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git merge 详细操作,看完就懂相关的知识,希望对你有一定的参考价值。
[root@hostname git_test]# git init hint: Using \'master\' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of \'master\' are \'main\', \'trunk\' and hint: \'development\'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty Git repository in /root/git_test/.git/ [root@hostname git_test]# git log fatal: your current branch \'master\' does not have any commits yet [root@hostname git_test]# vi test.txt [root@hostname git_test]# git add . [root@hostname git_test]# git commit "in main, 1st change" error: pathspec \'in main, 1st change\' did not match any file(s) known to git [root@hostname git_test]# git commit -m "in main, 1st change" [master (root-commit) 5c0420f] in main, 1st change 1 file changed, 1 insertion(+) create mode 100644 test.txt [root@hostname git_test]# git commit "in main, 1st change"^C [root@hostname git_test]# vi test.txt [root@hostname git_test]# git add . [root@hostname git_test]# git commit -m "in main, 2nd change" [master 16e9a53] in main, 2nd change 1 file changed, 1 insertion(+) [root@hostname git_test]# gi tlog bash: gi: command not found... Similar command is: \'go\' [root@hostname git_test]# git log commit 16e9a53302c804d3a0ad7924c45e00209c86c72f (HEAD -> master) Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:49 2023 -0400 in main, 2nd change commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:23 2023 -0400 in main, 1st change [root@hostname git_test]# git checkout -b feature_1 Switched to a new branch \'feature_1\' [root@hostname git_test]# vi test.txt [root@hostname git_test]# git add . [root@hostname git_test]# git commit -m "after branching, in feature_1, 1st change" [feature_1 11981bf] after branching, in feature_1, 1st change 1 file changed, 1 insertion(+) [root@hostname git_test]# git checkout master Switched to branch \'master\' [root@hostname git_test]# vi test.txt [root@hostname git_test]# git add . [root@hostname git_test]# git commit -m "after branching, in main, 1st change" [master 129c297] after branching, in main, 1st change 1 file changed, 1 insertion(+) [root@hostname git_test]# vi test.txt [root@hostname git_test]# git add . [root@hostname git_test]# git commit -m "after branching, in main, 2nd change" [master 87d7da3] after branching, in main, 2nd change 1 file changed, 1 insertion(+) [root@hostname git_test]# git checkout feature_1 Switched to branch \'feature_1\' [root@hostname git_test]# vi test.txt [root@hostname git_test]# git add . [root@hostname git_test]# git commit -m "after branching, in feature_1, 2nd change" [feature_1 c170207] after branching, in feature_1, 2nd change 1 file changed, 1 insertion(+) [root@hostname git_test]# git log commit c170207b0567946eff71880ee90326ad64822b0b (HEAD -> feature_1) Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:46:46 2023 -0400 after branching, in feature_1, 2nd change commit 11981bffedb873679d73bdca89716f1b6cbc9f4d Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:42:58 2023 -0400 after branching, in feature_1, 1st change commit 16e9a53302c804d3a0ad7924c45e00209c86c72f Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:49 2023 -0400 in main, 2nd change commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:23 2023 -0400 in main, 1st change [root@hostname git_test]# git checkout master Switched to branch \'master\' [root@hostname git_test]# vi test.txt [root@hostname git_test]# git add . [root@hostname git_test]# git commit -m "after branching, in main, 3rd change" [master 687068c] after branching, in main, 3rd change 1 file changed, 1 insertion(+) [root@hostname git_test]# git log commit 687068ce78e7f72326ecaec4c4d062139cd4d2c3 (HEAD -> master) Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:48:29 2023 -0400 after branching, in main, 3rd change commit 87d7da3f4a51f811a846451bb75f7f8ccbd7cca0 Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:44:23 2023 -0400 after branching, in main, 2nd change commit 129c297f2ac32868f60a6cee4fc76970090648ab Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:43:46 2023 -0400 after branching, in main, 1st change commit 16e9a53302c804d3a0ad7924c45e00209c86c72f Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:49 2023 -0400 in main, 2nd change commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:23 2023 -0400 in main, 1st change [root@hostname git_test]# git checkout feature_1 Switched to branch \'feature_1\' [root@hostname git_test]# git log commit c170207b0567946eff71880ee90326ad64822b0b (HEAD -> feature_1) Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:46:46 2023 -0400 after branching, in feature_1, 2nd change commit 11981bffedb873679d73bdca89716f1b6cbc9f4d Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:42:58 2023 -0400 after branching, in feature_1, 1st change commit 16e9a53302c804d3a0ad7924c45e00209c86c72f Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:49 2023 -0400 in main, 2nd change commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:23 2023 -0400 in main, 1st change [root@hostname git_test]# git merge master Auto-merging test.txt CONFLICT (content): Merge conflict in test.txt Automatic merge failed; fix conflicts and then commit the result. [root@hostname git_test]# vi test.txt [root@hostname git_test]# git status On branch feature_1 You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: test.txt no changes added to commit (use "git add" and/or "git commit -a") [root@hostname git_test]# git add . [root@hostname git_test]# git commit -m "merge main, fix conflict" [feature_1 ed8959d] merge main, fix conflict git log shows all the commits from master branch and feature_1 branch are included [root@hostname git_test]# git log commit ed8959dd5f7c200c9e45e69a1804ecb83b3cf89e (HEAD -> feature_1) Merge: c170207 687068c Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:54:42 2023 -0400 merge main, fix conflict commit 687068ce78e7f72326ecaec4c4d062139cd4d2c3 (master) Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:48:29 2023 -0400 after branching, in main, 3rd change commit c170207b0567946eff71880ee90326ad64822b0b Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:46:46 2023 -0400 after branching, in feature_1, 2nd change commit 87d7da3f4a51f811a846451bb75f7f8ccbd7cca0 Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:44:23 2023 -0400 after branching, in main, 2nd change commit 129c297f2ac32868f60a6cee4fc76970090648ab Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:43:46 2023 -0400 after branching, in main, 1st change commit 11981bffedb873679d73bdca89716f1b6cbc9f4d Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:42:58 2023 -0400 after branching, in feature_1, 1st change commit 16e9a53302c804d3a0ad7924c45e00209c86c72f Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:49 2023 -0400 in main, 2nd change commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:23 2023 -0400 in main, 1st change [root@hostname git_test]# git diff 11981bffedb873679d73bdca89716f1b6cbc9f4d 129c297f2ac32868f60a6cee4fc76970090648ab diff --git a/test.txt b/test.txt index 0681d7f..4e4c571 100644 --- a/test.txt +++ b/test.txt @@ -1,3 +1,3 @@ in main, 1st change in main, 2nd change -after branching, in feature_1, 1st change +after branching, in main, 1st change [root@hostname git_test]# git diff 11981bffedb873679d73bdca89716f1b6cbc9f4d 129c297f2ac32868f60a6cee4fc76970090648ab diff --git a/test.txt b/test.txt index 0681d7f..4e4c571 100644 --- a/test.txt +++ b/test.txt @@ -1,3 +1,3 @@ in main, 1st change in main, 2nd change -after branching, in feature_1, 1st change +after branching, in main, 1st change [root@hostname git_test]# git rebase -i 16e9a53302c804d3a0ad7924c45e00209c86c72f [detached HEAD d2b1d01] after branching, in feature_1, 1st change Date: Fri Apr 21 22:42:58 2023 -0400 1 file changed, 2 insertions(+) Auto-merging test.txt CONFLICT (content): Merge conflict in test.txt error: could not apply 129c297... after branching, in main, 1st change Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply 129c297... after branching, in main, 1st change in the pop up file: pick 11981bf after branching, in feature_1, 1st change s c170207 after branching, in feature_1, 2nd change pick 129c297 after branching, in main, 1st change pick 87d7da3 after branching, in main, 2nd change pick 687068c after branching, in main, 3rd change # Rebase 16e9a53..ed8959d onto 16e9a53 (5 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit\'s log message # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with \'git rebase --continue\') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit\'s # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. Conflict: [root@hostname git_test]# vi test.txt in main, 1st change in main, 2nd change <<<<<<< HEAD after branching, in feature_1, 1st change after branching, in feature_1, 2nd change ======= after branching, in main, 1st change >>>>>>> 129c297 (after branching, in main, 1st change) [root@hostname git_test]# git add . [root@hostname git_test]# git rebase --continue [detached HEAD d1ac649] after branching, in main, 1st change 1 file changed, 1 insertion(+) Successfully rebased and updated refs/heads/feature_1. 再次git log, 发现merge 那次记录没有了? [root@hostname git_test]# git log commit 4c6b9d68e4312a61e36f4bb95cad64f080d11d13 (HEAD -> feature_1) Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:48:29 2023 -0400 after branching, in main, 3rd change commit fb2d8d2de1a02a1c3d930ec68f20ea6955cd6f8a Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:44:23 2023 -0400 after branching, in main, 2nd change commit d1ac6493ba37454002009bf92a83363220a68e09 Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:43:46 2023 -0400 after branching, in main, 1st change commit d2b1d01d56705e26cc23a819c23e7a3d48c38104 Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:42:58 2023 -0400 after branching, in feature_1, 1st change after branching, in feature_1, 2nd change commit 16e9a53302c804d3a0ad7924c45e00209c86c72f Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:49 2023 -0400 in main, 2nd change commit 5c0420f6c5efb9c8b98c89b9d4595f15c3fbed9c Author: Shuai Ma <shuai.ma@hei-ya.com> Date: Fri Apr 21 22:41:23 2023 -0400 in main, 1st change [root@hostname git_test]# git diff 16e9a53302c804d3a0ad7924c45e00209c86c72f d2b1d01d56705e26cc23a819c23e7a3d48c38104 diff --git a/test.txt b/test.txt index ff7d9a6..0a69e58 100644 --- a/test.txt +++ b/test.txt @@ -1,2 +1,4 @@ in main, 1st change in main, 2nd change +after branching, in feature_1, 1st change +after branching, in feature_1, 2nd change [root@hostname git_test]# git diff d2b1d01d56705e26cc23a819c23e7a3d48c38104 d1ac6493ba37454002009bf92a83363220a68e09 diff --git a/test.txt b/test.txt index 0a69e58..3469806 100644 --- a/test.txt +++ b/test.txt @@ -2,3 +2,4 @@ in main, 1st change in main, 2nd change after branching, in feature_1, 1st change after branching, in feature_1, 2nd change +after branching, in main, 1st change [root@hostname git_test]#
看完就懂GD32替代STM32全过程记录
文章目录
【看完就懂】GD32替代STM32全过程记录
读完这一篇文章,你能获得的知识点:
- GD32与STM32基本区别
- STM32CubeMX程序修改后如何下载到GD32
- GD32移植后一些外设的测试
一、前言
最近半导体行业出现的缺货浪潮,各种芯片价格飙升,像一些常用芯片如STM32F103C8T6,从去年的5块一片涨价到现在的65一片,涨幅17倍!!!在这种情况下,大家纷纷在找一些国产芯片来替代ST的芯片,而在国产中做的比较好的芯片就是兆易创新的GD32芯片了,我最近也本着学习的心态研究了一下GD32快速替换STM32的方式,使用GD32F303VCT6替换STM32F103VCT6,以此为例做一些记录分享给大家
二、GD32与STM32
GD32是由北京兆易创新开发的国产32位MCU,基于Arm Cortex- M3/M23/M4内核以及RISC-V内核的32位通用微控制器,与STM32相比,CPU主频更高,内存更多,外设更丰富。其众多产品是以STM32芯片为模板,基于STM32的底层寄存器地址进行正向研发,部分产品可以直接PIN TO PIN替代STM32的芯片,部分型号可以直接以STM32的程序做部分修改后直接烧入进GD32中运行,例如GD32E103、GD32F10x、GD32F30x都是和STM32F10x系列是完全PIN TO PIN兼容的,内部地址寄存器完全兼容,唯一区别只是内核不同,但在使用外设时影响不会很大,下面的文章我也围绕GD32替代STM32F10x系列的芯片展开叙述
选项 | GD32F10x系列特性 | GD32F30x系列特性 | STM32F10x系列特性 |
---|---|---|---|
CPU及Flash特性 | 高达108MHz主频 高达3M Flash 前256K Flash零等待 | 高达120MHz主频 高达3M Flash 前256K Flash零等待 | 72M主频,512KFlash |
片内外设特性 | 高达3个12位ADC; 高达2个12位DAC; 高达10个通用16位定时器,2个基本定时器和2个增强型定时器; 高达3个SPI、2个I2C、5个USART/UART、2个I2S、2个CAN、1个全速USBD、1个全速USBFS、1个以太网MAC | 高达3个12位ADC; 高达2个12位DAC; 高达10个通用16位定时器,2个基本定时器和2个增强型定时器; 高达3个SPI、2个I2C、5个USART/UART、2个I2S、2个CAN、1个全速USBD、1个全速USBFS、1个以太网MAC | 3个ADC,2个DAC,4个通用TIM,2个高级TIM,2个基本TIM,3个SPI,2个I2C,5个USART,1个USB,1个CAN,1个SDIO |
其他特性 | 36~144 PIN;具有SDIO模块; | 36~144 PIN 具有SDIO模块; | 36~144 PIN 具有SDIO模块; |
相同点
- 芯片的型号命名方式相同,而且相同信号的引脚定义基本相同,具体命名规范如下
-
函数库文件基本相同:因为GD32正向研发,对于PIN TO PIN的芯片,内部寄存器地址和STM32完全相同,所以STM32的库文件编译后的文件可以直接下载
-
编译工具相同如keil、IAR都相同
不同点
-
工作电压有所不同,STM32的工作电压在2.0~ 3.6V或1.65~ 3.6V,GD32的工作电压在 2.6~3.6V,工作范围相对要窄。
-
GD32F303/F103主频比STM32F103主频要高,适合一些更快的计算中
-
GD32提高了相同工作频率下的代码执行速度,所以GD32的_NOP()时间比STM32更加短,所以不使用定时器做延时时要注意修改
-
GD32的flash擦除时间要比STM32更长
-
功耗上GD32的功耗要相对高一点
-
GD32的BOOT0必须接10K下拉或接GND,ST可悬空,这点很重要。
-
RC复位电路必须要有,否则MCU可能不能正常工作,ST的有时候可以不要。
-
GD的swd接口驱动能力比ST弱,可以有如下几种方式解决:
a、线尽可能短一些;
b、降低SWD通讯速率;
c、SWDIO接10k上拉,SWCLK接10k下拉。 -
GD对时序要求严格,配置外设需要先打开时钟,在进行外设配置,否则可能导致外设无法配置成功;ST的可以先配置在开时钟。
-
修改外部晶振起振超时时间,不用外部晶振可跳过这步。
原因:GD与ST的启动时间存在差异,为了让GD MCU更准确复位(不修改可能无法复位)。
三、程序下载方法
在使用GD的标准库开发时,可以使用J-Link、DAP在编译器内可以进行下载程序和在线仿真
在使用STM32的库进行开发时,因为芯片不对应,无法进行仿真,但在程序验证之后可以直接移植到对于芯片PIN TO PIN的GD芯片之中,具体下载方式有通过J-LinkFlash或者GD-Link下载hex,或者跳过FlyMCU经过USB转TTL和串口1连接下载程序,还有一种跳过DFU下载这个我没有尝试过,下面我就具体讲一下J-Link下载和FlyMCU串口下载到GD32 (该下载方法对ST和GD都有效)
准备条件:
- 首先我们有一个STM32F103VCT6的点灯工程hex,通过CubeMX配置,具体教程看我之前的文章:点灯链接,这里因为要移植到GD32,需要修改工程里面的HSE超时时间,具体位置在生成代码的如下位置,把值改大就行,不改大会影响复位正常运行!!!改完生成新的hex文件
- JFlashARM.exe软件
- J-Link连接电脑与GD32F303
操作步骤:
- 打开软件,点击设置,进入工程设置
- 设置下载模式,这里我用的SWD下载
- 设置下载的目标对象-STM32F103VCT6
- 设置Auto下载时的操作
- 设置完成回到主界面,点击open打开hex文件
- 点击连接,连接jlink和芯片
- 点击auto进行下载程序
- 下载后可能出现ERROR: Could not start CPU core. (ErrorCode: -1)报错,但是不影响,只要出现下面框选的内容就代表程序下载完成,出现报错可能的原因是因为我使用的M3内核程序下载到M4内核单片机,软件复位启动后会报错,但实际上已经自动复位完成了,如果不想出现报错,把auto里面最好一个选项取消勾选,就不会有报错了,但这样需要自己硬件复位程序。还有一个注意点,每次hex重新生成后需要重新再打开一次hex文件,可能是JFlash版本问题。
准备条件:
- USB转TTL模块连接GD32单片机
- FlyMcu下载软件
- 一个STM32F103VCT6的点灯工程hex和上面的相同
操作步骤:
- 将USB转TTL与单片机串口1连接,同时保证两边共地,及USB转TTL的TX接PA10,RX接PA9,GND与GND连接VCC可接可不接,但如果接了电压要接到相同的,不要接错,接完将USB转TTL插到电脑上
- 打开FlyMcu,选择串口连接,波特率设置为115200,过高不稳定,过低下载慢,根据自己需求来
- 选择打开hex文件
- 选择STMISP,同时配置模式为不使用RTS和DTR,因为我的USB转TTL是直接连接到单片机串口1的,其他的模式需要配合一些电路设计,具体可以百度
-
将单片机的Boot0拉高Boot1拉低,原因(参考百度):这样设置启动方式为系统存储器启动方式,从系统存储器启动,该模式的启动程序功能是由厂家设置的。一般来说,这样的启动方式用的比较少。系统存储器是芯片内部一块特定的区域,GD32在出厂时,由GD在这个区域内部预置了一段BootLoader,也就是我们常说的ISP程序,这是一块ROM,出厂后无法改动。一般来说,我们选用这样的启动模式时,是为了从串口下载程序,由于在厂家提供的BootLoader中,提供了串口下载程序的固件,能够通过这个BootLoader将程序下载到系统的Flash中。该下载方式须要下面步骤:
-
将BOOT0设置为1,BOOT1设置为0,然后按下复位键,这样才干从系统存储器启动BootLoader
-
最后在BootLoader的帮助下,通过串口下载程序到Flash中
-
6.在FlyMcu中点击下载,之后按下开发板复位按键,程序显示下载,下载完成如下
- 将boot0插回低电平,复位芯片运行程序
GD32直接下载STM32 Hal库开发的程序运行完成
四、使用CubeMX开发GD32测试
这一栏是我用STM32CubeMX进行开发,并下载到GD32F303VCT6的芯片上运行,观察移植效果的一些记录,测试会一直更新,并且将我遇到的反馈效果记录下来,给后面同学做参考
- HAL库开发测试GPIO输出,1S灯的电平反转一次
测试效果:完美运行,示波器看了电平变化间隔,精度挺高
- HAL库开发测试串口1输出数据,1S发送一次信息
测试效果:时间戳观察,符合预期现象,下次使用逻辑分析仪看一下具体波形和STM32做对比!
因为笔者水平原因,文章有错误或者改进之处希望大佬可以在评论区提出来,或者私信我,万分感谢!!!
以上是关于git merge 详细操作,看完就懂的主要内容,如果未能解决你的问题,请参考以下文章