创建新的repo

有时我们只是希望在本地管理好自己的代码,并不需要在云端有一个repo,这个时候可以如下方法使用git

  • Create a directory to contain the project.
  • Go into the new directory.
  • Type git init.
  • Write some code.
  • Type git add to add the files .
  • Type git commit.

git cherry-pick

git cherry-pick是将指定的提交应用于其他分支。

  1. git cherry-pick <commit Hash>

例:将feature分之的f应用到master

cherry pick操作前
image.png

  1. git checkout master
  2. git cherry-pick f

经过操作则变为
image.png

git cherry-pick命令的参数,也可以是分支名称

  1. git cherry-pick feature

cherry pick支持一次转移多个提交

  1. git cherry-pick <HashA> <HashB>
  2. git cherry-pick A..B #转移一系列的连续提交,但是提交A不会包含再Cherry pick中
  3. git cherry-pick A^..B #提交A也包含在cherry pick中

解决代码冲突

—continue
用户解决代码冲突后,第一步将修改的文件加入暂存区(git add .),第二步使用git cherry-pick --continue让cherry pick过程继续执行。

—abort
发生代码冲突后,放弃合并,回到操作以前的样子

—quit
发生代码冲突后,退出Cherry pick,但是不会倒操作前的样子

参考资料

https://kbroman.org/github_tutorial/pages/init.html
https://www.ruanyifeng.com/blog/2020/04/git-cherry-pick.html