Here’s an example. I made a couple of changes to my README file. These changes were done twice. In the first commit, I wrote the message that these were README changes. In the second edit, I made some formatting chnages to the README. Obviously I didnt want the kernel source to have two commits just for README. So I wanted to amend the last commit to take care of the new changes too and push to last commit.
So I tried that:
First push:
[[email protected] kernel_IN]$git commit -a [master df5f8a1] Android README info A few more .gitignore files 2 files changed, 32 insertions(+), 376 deletions(-) rewrite README (99%) [[email protected] kernel_IN]$git push origin master Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 935 bytes, done. Total 4 (delta 2), reused 0 (delta 0) remote: bb/acl: droidzone is allowed. accepted payload. To ssh://[email protected]/droidzone/kernel_android_n7100_v1.git 11aa64f..df5f8a1 master -> master
Now I made the changes I wanted.
[[email protected] kernel_IN]$emacs README
Now changing the last commit message:
[[email protected] kernel_IN]$git commit --all --amend [master 8b34f1d] Android README info A few more .gitignore files 2 files changed, 32 insertions(+), 376 deletions(-) rewrite README (99%)
Now I try to push. I get a failed message because the same commit exists on remote and is different.
[[email protected] kernel_IN]$git push origin master To ssh://[email protected]/droidzone/kernel_android_n7100_v1.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'ssh://[email protected]/droidzone/kernel_android_n7100_v1.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
So it asked me to pull. I try that. Obviously there’s a conflict again.
[[email protected] kernel_IN]$git pull Auto-merging README CONFLICT (content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result.
Fine. So I need to merge the conflicts manually.
[[email protected] kernel_IN]$git mergetool merge tool candidates: opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse ecmerge p4merge araxis bc3 emerge vimdiff Merging: README Normal merge conflict for 'README': {local}: modified file {remote}: modified file Hit return to start merge resolution tool (kdiff3):
Now it opened the nice GUI where I’m able to compare the three files and edit each one, then choose one of them.
I chose to use File B for all.
On closing the tool, this happened.
Next I have to commit afresh:
[[email protected] kernel_IN]$git commit -a [master 0ee33d2] Merge branch 'master' of ssh://bitbucket.org/droidzone/kernel_android_n7100_v1
It automatically added the commit message as a merge conflict resolution commit.
Now I can push the changes.
[[email protected] kernel_IN]$git push Counting objects: 8, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 577 bytes, done. Total 4 (delta 2), reused 0 (delta 0) remote: bb/acl: droidzone is allowed. accepted payload. To ssh://[email protected]/droidzone/kernel_android_n7100_v1.git df5f8a1..0ee33d2 master -> master
In the end I suppose it didnt really offer advantages to amend changes and then make this additional commit. I know I’m missing a git command.
Joel G Mathew, known in tech circles by the pseudonym Droidzone, is an opensource and programming enthusiast.
He is a full stack developer, whose favorite languages are currently Python and Vue.js. He is also fluent in Javascript, Flutter/Dart, Perl, PHP, SQL, C and bash shell scripting. He loves Linux, and can often be found tinkering with linux kernel code, and source code for GNU applications. He used to be an active developer on XDA forums, and his tinkered ROMS used to be very popular in the early 2000s.
His favorite pastime is grappling with GNU compilers, discovering newer Linux secrets, writing scripts, hacking roms, and programs (nothing illegal), reading, blogging. and testing out the latest gadgets.
When away from the tech world, Dr Joel G. Mathew is a practising ENT Surgeon, busy with surgeries and clinical practise.