$ git commit -m " merge master readme.txt"
U bootAnimation.rar
error: commit is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
$ git merge master
warning: Cannot merge binary files: bootAnimation.rar (HEAD vs. master)
Auto-merging bootAnimation.rar
CONFLICT (content): Merge conflict in bootAnimation.rar
Automatic merge failed; fix conflicts and then commit the result.
Administrator@O77FK7TWI5CW8GV MINGW64 /d/pengxing/git/git_bin (h20_d_zb_student|MERGING)
$ git commit "use h20_d_zb_student bootAnimation.rar"
fatal: cannot do a partial commit during a merge.
Administrator@O77FK7TWI5CW8GV MINGW64 /d/pengxing/git/git_bin (h20_d_zb_student|MERGING)
// 现在h20_d_zb_student 处于MERGING 冲突状态。
git - How to cherry pick only changes for only one file, not the whole commit
情况:
1. master 分支上面有一个 开机动画库文件 boot.rar
2. 创建基于master的分支 student, 替换之前开机动画库boot.rar
3. 在master分支上面进行修改BUG
4. 现在需要将master的修改同步的student分支上面
结果:
只是将master的修改文件同步到student当中,但开机动画库不变boot.rar
方案一
1. 切换成student分支上面 git checkout student
2. 合并master分支 git merge master (会提示
Cannot merge binary files: bootAnimation.rar (HEAD vs. master))3. student分支上面boot.rar库还没有变化,但master上面的修改BUG已经同步上面了,此分支状态 student|merge状态,说明处理合并冲突状态
4. 因为我们不希望合并,其直接做一个添加操作 git add bootAnimation.rar
5. 提交此次合并操作 git commit –m “merge master and not replace bootAnimation.rar”
注意:
就算误操作合并成功,将master上面的文件替换student上面的bootAnimation.rar。
我们可以在student分支上,将之前的bootAnimation.rar版本读取出来。然后添加,然后提交修改
commit 35c30492e312e9d0b1ecf9f336b39fc3c0048d8f
Author: pengxinglove <pengxinglove@qq.com>
Date: Wed Feb 17 09:37:45 2016 +0800add bootAnimaition.rar
diff --git a/bootAnimation.rar b/bootAnimation.rar
new file mode 100644
index 0000000..b590627
Binary files /dev/null and b/bootAnimation.rar differAdministrator@O77FK7TWI5CW8GV MINGW64 /d/pengxing/git/git_bin (master)
$ git checkout 35c304 -- bootAnimation.rar
1. git checkout student
2. git checkout 35c304 -- bootAnimation.rar
3. git comm –m “取回35c304 版本的 bootAnimation.rar “
git checkout <branch> – filename 可以取回指定commit上面的文件, branch 本质就是commit对象
If you want the contents of the file to be the same as on the target branch, you can use git checkout <branch> -- <filename>
. This will however not “cherry-pick” the changes that happened in a single commit, but just take the resulting state of said file. So if you added a line in a commit, but previous commits changed more, and you only want to add that line without those other changes, then a checkout is not what you want.
扩展:
git checkout
1. 本质是从版本库当中读取文件,如果需要从版本库当中读取文件,就可以想使用此命令
2. 默认是读取当前分支的全部文件
3. 如果想读取某一个分支或某一次提交下的文件,只要指明配置参数 git checkout branchname –- bootAnimation.rar
git log
1. 本质查看历史操作信息,对于指定文件的操作,对于历史提交的操作,如果需要查看历史操作信息就可以使用此命令
2. 如查看指定文件的历史操作信息 git log -- path/to/your/file (注意之间有空格)
分支与commit id
1. 分支与commit id 其的本质是相同的。分支是commit id的别名,方便当前使用。
2. commit id 其能够适应于所有情况