Thursday, February 13, 2014

How to git commit --amend


If you have multiple commits, you can either squash your commit or amend your commit. Below are the steps to amend your commit

myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)
$ git add .

myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)
$ git commit --amend

This will open the vi editor, change the commit message and then exit [wq]

[ta1747 cb03152] ta1747 - Change the upload URL
 2 files changed, 5 insertions(+), 3 deletions(-)

myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)
$ git log
commit cb0315286b26e69f8d58b4262e35394101e18150
Author: David Sundersingh
Date:   Thu Feb 13 11:53:06 2014 -0800

    ta1747 - Change the upload URL


myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)
$ git diff rewrite
myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)
$ git push origin +ta1747

Counting objects: 41, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (21/21), 1.64 KiB | 0 bytes/s, done.
Total 21 (delta 14), reused 0 (delta 0)
To git@gitserver:myname/alfresco-dev.git
 + 16ff671...cb03152 ta1747 -> ta1747 (forced update)

How to resolve git merge conflicts: How to git rebase --skip if git rebase --continue does not work

myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)
$ git rebase rewrite
First, rewinding head to replay your work on top of it...
Applying: Change upload URL
Using index info to reconstruct a base tree...
M       src/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/com/mycompany/se/rewrite/src/models/attachment.js
:11: trailing whitespace.
        // change the URL to avoid login authentication
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging src/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/com/mycompany/se/rewrite/src/models/attachment.js
CONFLICT (content): Merge conflict in src/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/com/mycompany/se/rewrite/src/models/attachment.js
Failed to merge in the changes.
Patch failed at 0001 Change upload URL to /share/proxy/alfresco
The copy of the patch that failed is found in:
   c:/Users/myname/mynames-alfresco-dev/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".


myname@myname-WS /c/Users/myname/mynames-alfresco-dev ((f8bf9f1...)|REBASE 1/1)
$ git status
# HEAD detached at f8bf9f1
# You are currently rebasing branch 'ta1747' on 'f8bf9f1'.
#   (fix conflicts and then run "git rebase --continue")
#   (use "git rebase --skip" to skip this patch)
#   (use "git rebase --abort" to check out the original branch)
#
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       modified:   src/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/com/mycompany/se/rewrite/src/views/browse-files/browse-files-template.ftl
#
# Unmerged paths:
#   (use "git reset HEAD ..." to unstage)
#   (use "git add ..." to mark resolution)
#
#       both modified:      src/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/com/mycompany/se/rewrite/src/models/attachment.js
#

myname@myname-WS /c/Users/myname/mynames-alfresco-dev ((f8bf9f1...)|REBASE 1/1)
$ git add .

myname@myname-WS /c/Users/myname/mynames-alfresco-dev ((f8bf9f1...)|REBASE 1/1)
$ git commit -m "Resolve conflicts while rebasing file upload URL changes"
[detached HEAD 16ff671] Resolve conflicts while rebasing file upload URL changes
 2 files changed, 6 insertions(+), 4 deletions(-)

myname@myname-WS /c/Users/myname/mynames-alfresco-dev ((16ff671...)|REBASE 1/1)
$ git rebase --continue
Applying: Change upload URL to /share/proxy/alfresco
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".


At this stage git rebase continue did not work, so instead use git rebase --skip

myname@myname-WS /c/Users/myname/mynames-alfresco-dev ((16ff671...)|REBASE 1/1)
$ git rebase --skip

myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)
$ git diff rewrite

Since I already had a open merge request, this push will update the existing merge request

myname@myname-WS /c/Users/myname/mynames-alfresco-dev (ta1747)

$ git push origin +ta1747 (This forces the update similar to git push -f)