git 一些常用的场景

列举一些常用的使用场景

1. 将分支A上的一个commit合并到分支B上。

1> 首先切换到 A分支, 查看log,找到对应的commit ID

git checkout  branch_A

git log

2> 然后切换到B分支上

git checkout  branch_B

3> 把分支A的某个commit合并到了分支B

git cherry-pick  commit_id_xxx

4> 注,此时可能会有一些文件冲突,并有对应的提示。需要手动修改

可用 git status 查看需要修改的文件。最后要  git commit

 2. 从主分支merge 最新代码到个人分支

1> 拉取 所有分支

 git fetch

2> 使用git栈 存储 本地的修改

 git  stash

3> 合并分支

 git merge --no-ff origin/featur/branch_xx

4> handle conflicts

5> git add -A

6> git commit -m "Meger module context"

3. 忽略 文件中的 ^M

git  config  --global  core.whitespace  cr-at-eol

4. git diff 查看不同

git diff  commit_id1  commit_id2  查看两个版本之间的差异

git diff  commit_id1:filename   commit_id2:filename  查看某两个版本的某个文件之间的差异

原文地址:https://www.cnblogs.com/jyfyonghu/p/11224341.html