git操作保存(转)

1、生成某次commit之后的patch

miyuehu@s6:~/repo/m$ git format-patch c92ec02610efac65d2bf979127541400416d1610
0001-add-build.sh.patch
0002-v1.4-released.patch


2、生成某次commit的patch

miyuehu@s6:~/repo/m$ git format-patch -1 c92ec02610efac65d2bf979127541400416d1610
0001-v1.4.patch


3、am patch出错后的处理

miyuehu@s6:~/repo/tmp$ git am < 0001-fix-bug-with.patch
Applying: fix bug with
/home/miyuehu/repo/tmp/.git/rebase-apply/patch:220: trailing whitespace.

/home/miyuehu/repo/tmp/.git/rebase-apply/patch:245: trailing whitespace.

error: patch failed: android/device/*.java:307
error: android/device/*.java: patch does not apply
error: patch failed: android/device/**.java:27
error: android/device/**.java: patch does not apply
error: patch failed: android/device/***.java:30
error: android/device/***.java: patch does not apply
Patch failed at 0001 fix bug with
The copy of the patch that failed is found in:
   /home/miyuehu/repo/tmp/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

此时,无需执行git am --continue/git am --skip/git am --abort

执行

miyuehu@s6:~/repo/tmp$ git apply --reject 0001-fix-bug-with.patch
0001-fix-bug-with.patch:21: trailing whitespace.
                                                Log.i(TAG, "post onFailure");
0001-fix-bug-with.patch:28: trailing whitespace.
                                                Log.i(TAG, "post onFinish");
0001-fix-bug-with.patch:35: trailing whitespace.
                                                Log.i(TAG, "post onStart");
0001-fix-bug-with.patch:42: trailing whitespace.
                                                Log.i(TAG, "post onSuccess");
0001-fix-bug-with.patch:55: trailing whitespace.
        FileInfo mFileInfo;
Checking patch android/device/*.java...
Checking patch android/device/**.java...
Checking patch android/device/***.java...
Applied patch android/device/*.java cleanly.
Applied patch android/device/**.java cleanly.
Applied patch android/device/***.java cleanly.
warning: squelched 24 whitespace errors
warning: 29 lines add whitespace errors.

执行

miyuehu@s6:~/repo/tmp$ git status
On branch v1.4
Your branch is up-to-date with 'origin/v1.4'.

You are in the middle of an am session.
  (fix conflicts and then run "git am --continue")
  (use "git am --skip" to skip this patch)
  (use "git am --abort" to restore the original branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   android/device/*.java
        modified:   android/device/**.java
        modified:   android/device/***.java
        modified:   "doc/100\345\215\207\347\272\247\346\226\207\346\241\243.doc"

PS:這里应该显示中文的,需要配置git

miyuehu@s6:~$ git config --global core.quotepath false
miyuehu@s6:~$ vim .gitconfig

[user]
        name = miyuehu
        email =
miyuehu@qq.com
[core]
        quotepath = false

這里git就能显示中文了。

miyuehu@s6:~/repo/tmp$ git status -uno
On branch v1.4
Your branch is ahead of 'origin/v1.4' by 7 commits.
  (use "git push" to publish your local commits)

You are in the middle of an am session.
  (fix conflicts and then run "git am --continue")
  (use "git am --skip" to skip this patch)
  (use "git am --abort" to restore the original branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   android/device/*.java
        modified:   android/device/**.java
        modified:   android/device/***.java
        modified:   doc/100升级文档.doc

执行

miyuehu@s6:~/repo/tmp$ git add android/device/*

fix conflicts and then run "git am --continue"

miyuehu@s6:~/repo/tmp$ git am --continue



————————————————————————————————————————

Git: Merging patches git am -3 vs git apply

Merging patches

When git-am fails to cleanly apply It will ask you to apply it yourself, to git add the file and to run git-am --resolved.
In fact, git-am can help you a lot. When the call to git-am for a patch fails, simply run :

git-am --3way

Il will merge the file that can be automatically merge. Some files may be marked with CONFLICT and in this case, edit them to do a manual merge, and once they are fixed and run

git add $FILES_IN_CONFLICT
git-am --resolved

Merging workflow

  • I’d recommend using File -> Save As, selecting “Raw Message Source”
    as the format, then apply using:

    % git am < /path/to/saved/message
  • Consider creating a topic branch for applying the patch and then
    merging that to master. e.g.

    % git checkout -b bugfix_from_john master
    % git am < /path/to/saved/message
  • Check things out. Make minor edits if needed. You can then use “git
    add” to add in your edits and “git commit –amend” to make those
    changes part of the patch the author sent.
  • Once you’re happy:
    % git checkout master
    % git merge bugfix_from_john
    % git branch -d bugfix_from_john

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值