Git – Reset to particular commit

List all commits from history, and choose the required commit.

[[email protected] kernel]$git log --pretty=oneline
8983d7058d2f6b7ff907328c53fc0e97d5c0f576 ^
832219061059f8d9af922a54bb935927c5bbedff New
b53e4b1de439e031bd50fe9aa4fd84dd51e2e438 Added missing
02086fc547c3ffbba4abf07327bb18cda3dfee0f Missing files
d6f61dadd035ef118231b4144ffcc05c6282212b More missing files added
ed26cc3c8c4709ad53bd9365394e6f40352f0461 Added files missed by buggy .gitignore rules
5ce7674d493bc1401f6aa45d3e817a839f3a21c5 Added some missing files
cd2cebfe9f70c07b00650faa21d28f9d6c50516a .Gitignore changes
d5c8c3f188672a5a1f8c8d5c959f0fe280e827c1 Toolchain location change
0ee33d2545676c5f38719ae0b1ccf539d987ac49 Merge branch 'master' of ssh://bitbucket.org/droidzone/kernel_android_n7100_v1
8b34f1deaaa4305ba31388946de098a784efc7d6 Android README info A few more .gitignore files
df5f8a17a25a2240ad7baf2651a1df1a366b25b6 Android README info A few more .gitignore files
11aa64f2d0fff0cda4753db88072b0a0f34816f6 Compiler errors: Fixes for the following error:
b9202d534b4a342cfd6baf914ddbace25b4c94df Fix for compiler errors: Switched always_inline
ea1e1b5cb75bde723fbc033d13546c34f990378b Fix for inlining error during compilation
404c50fe3e735581754c47e0ebb24e7ea1c15902 Compiler fixes?
e52b83584f9316422b18b7166fcfdecf218ed715 Disable module versioning
c299ec681a2c2c98f649701d7cb612a160421e7b Toolchain customizationsy
e260d9fd0c998a545ea8134f9c416f89592c10d8 Makefile changes: Added toolchain customization (NDK) gcc 4.4.3 .config: defconfig +   [x] Bzip2, lzma, xz com
5b6dbfb958551a6f0f8bbeb4bb9856ea64afac5c First commit

I want to reset to first commit and clean up the history too (so that it will be as if the commits following from that commit will cease to have ever existed).

[[email protected] kernel]$git reset --hard 5b6dbfb958551a6f0f8bbeb4bb9856ea64afac5c

As you can note, here the SHA of the first commit is entered.

You can confirm that the git has been taken back to first commit:

[[email protected] kernel]$git log
commit 5b6dbfb958551a6f0f8bbeb4bb9856ea64afac5c
Author: droidzone <[email protected]>
Date:   Mon Dec 24 23:01:32 2012 +0530

    First commit

    Samsung Galaxy Note2 N7100
    --------------------------
    - Droidzone www.droidzone.in
    - Support/Downloads: www.note2.droidzone.in

    Initial Modifications:
    [x] Based on Samsung IN Source Drop - GT-N7100_JB_Opensource.zip
    [x] Added cypress resistive touch button drivers from GT-N7100_HK_JB_Opensource.zip
        Samsung Source: http://opensource.samsung.com/

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Git force overwrite of untracked local files during a pull

I made some changes to .gitignore so that untracked files were formed in the repo. When I tried a pull, it failed:

[[email protected]] ~/kernel/kernel_android_n7100_v1 $git pull origin
Updating df5f8a1..d6f61da
error: The following untracked working tree files would be overwritten by merge:
        include/config/accessory.h
        include/config/aeabi.h
        include/config/alignment/trap.h
        include/config/android.h

So the solution was to do a:

git fetch --all
git reset --hard origin/master
[[email protected]] ~/kernel/kernel_android_n7100_v1 $git fetch --all
Fetching origin
[[email protected]] ~/kernel/kernel_android_n7100_v1 $git reset --hard origin/master
HEAD is now at d6f61da More missing files added

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

A look into git merge conflicts

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.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Automating Git for passwordless logins- Setup git key pairs and setup ~/.ssh/config file

I’ve already posted about how to create key pairs fo SSH elsehere.

This is a short listing of the ~/.ssh/config file used for Git:

Host goob
     HostName buildbot1.snipanet.com
     User droidzone
     IdentityFile ~/.ssh/privatekey_goo
     ServerAliveInterval 30
     ServerAliveCountMax 120
Host goo
     HostName upload.goo.com
     User droidzone
     IdentityFile ~/.ssh/privatekey_goo
     ServerAliveInterval 120
     ServerAliveCountMax 120
     Port 2222
Host xda
     HostName build1.dev.xda-developers.com
     User droidzone
     IdentityFile ~/.ssh/xdamachine_key_openssh_pvt
     ServerAliveInterval 30
     ServerAliveCountMax 120
Host sf
     HostName shell.sourceforge.net
     User droidzone
     IdentityFile ~/.ssh/privatekey_sourceforge_ssh
     ServerAliveInterval 30
     ServerAliveCountMax 120
Host bitbucket.org
    IdentityFile ~/.ssh/id_rsa_bitbucket

 

Anatomy of a config file
A config file should be named ~/.ssh/config
The permissions of each key referred to by ssh should be restricted to user only, i.e chmod go=
The “Host” value is an alias
The “Hostname” value should be an ip or actual resolvable hostname
If Port is not 22, it should be specified in the file.

If the hostname is correct, you can login to sourceforge by typing: ssh sf
The username, hostname, key, port will be determined from the file.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Excluding a directory anywhere in the source tree from git

Just add the following line to your .gitignore file (the file should be located in the root of the git repo):

include/

Excludes all directories named include. Suppose I’m in /home/droidzone/kernel and there are subdirectories like the following:

/home/droidzone/kernel/include
/home/droidzone/kernel/arch/arm/include
/home/droidzone/kernel/exynos/include

The above rule will stop git from tracking all these directories.

In most cases the directory had already been tracked by the time you added the gitignore rule. In such an instance you can remove all these tracked directories from the git with the following:

git rm --cached -r include/

To be effective it should be combined with a .gitignore rule.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Generate patches for all commits

This one is about creating a bunch of patches for each commit.

First list all commits by commit hash

git log --pretty=oneline

which produces this:

[email protected]:~/Note2Core-GT-N710x_Kernel$ git log --pretty=oneline
db31b055b9096f8350144438901af6925b4629e3 sched: don't call task_group() many times in set_task_rq()
ce6efedc9eae826d328f96dfc664e609225cffe9 CPU unaligned access path
1ca9237911877f76cd60c950b8c1826b5ad4b2c4 Added -pipe to primary makefile
29369e159661e51c5192df960fd78c5d7eeb289d sensors: update device sensors
a40c7009bde4d620fe561ca087726be4eaa7de9c add Triangle Away (chainfire) support
96104e2a18a619521d0c204a53640334e7d46665 small cleanup to makefile
37a5d18b8d3a29b8671476cc3b090cad3212a556 sound-soc: Sound platform and WM1811 changes
5e84a63dbbf3255b26e43446e29862972bf5670e note2core defconfigs update 1.05
e94bee447115f56a6a0e2b701ba6f4dd71bc9e69 fix config selection of 1.8ghz and FSync
a889fed4ccf8105822874bf82e05c819d2f119d9 mach-exynos: cpuidle-exynos4: set logging default to disabled
3c4092a30eb23e5c817a694e246923b41e39f6d6 another fix to cpu frequency tables
2b0b02a53fa915da06c1519a5c1559c31cc126a1 fix to cpu frequency tables
2c305d77b1ebd8a45242312ae693764de11630a9 Corrected makefile
6b816ffb7b9b3d48554424c668aa24153c1518ca note2core defconfigs v1.04 for non LTE and LTE
25593b3670db08687f1dfe7bba7acc81d6658c9b fix a build error if debugfs disabled
2463f4382e8539001b2368a0fa91e914955e6336 some minor crypto changes
ecbd8f920d4b05102b5bdf8661350424e9af9f25 CRC32 slicing-by-8 algorithm
5c43b013b61a074e8c0a40ae233033926fde1e63 Add optimized ARM RWSEM algorithm, and enable in config  Credit:Ezekeel
ea9f634c636947b9824207cf981c3fd7f6c25972 lib/sha1: use the GIT implementation of SHA-1
cf57b5fbe2460be6b589ee6e53d258237d3b8f4f arm: remove 'optimized' SHA1 routines
84dddf910dcfb8d53a5efb3d7e2f408c8438651b kernel: make an exception in module loading to load proprietary modules Credit:gokhanmoral
5cfc710720e602b41548f152d4accebd894295af arm:remove stale export of 'sha_transform'
b7765c83b1608e6c956ecf2bd68b38ab2ca59693 lib/memcopy: use glibc version Credit:faux123
4d659526b2cd2ac4ea8f2fe6d102b24cf7f5773e lib/string: use glibc version Credit:faux123
413abc3ec2e4ce9046d4745c84ec4fdd85d2fd7b Sensorhub - fix firmware mislabelling and version check - Credit:Andreilux
ce730621b834433db9f91f50f59606e093840ccd Add 1.6/1.8ghz optional cpu frequency table (1.8ghz frequency table credit to Andreilux) and voltage control interface
84c03d4fac7145a06199cfbe306ddbef66b70394 reduce busfrequency increase threshold
0b8e0522b367758607c25f9e55d7e283d0c3fb0f Fix build error if debugfs disabled
a3b3d407e7031e846c222662211c102e8672f170 Always mount all partitions with noatime
a639d7355d6a89d8dcf67d8e7b54d02b4ade5aed Add optional FSync() disable
e74fced9a02942fd34813b3366635cd9cabc2aa0 disable some multicasting during sleep Credit:Andreilux
d19729546a80f1eba64c7885658cffe44feb2b72 fix usb gadget build error if debugfs disabled
24c407a2d5d6ee88ee3b879ad730ea0a24211e10 remove mali state tracking, adjust mali dvfs utilisation steps
d7130a2f16e908f329f63ad2f260d3f5df9888b1 remove double MALI kconfig entry
2c8cfb8f62937a6a5aeb699a4ff5ceb6bc929303 remove debugging from MMC
5e61f07bdadedf5580443074503e5284c6c3daba disable GENTLE FAIR SLEEPERS, enable HRTICK
30fb717fa19b6a913366bdfd929874ab60c0208d add support for customised VM memory settings and readahead
e594a15d06d12c1b64b5a045518ad9b0fc32dca3 little name tweak to kernel version
e3e97b139aedc7c5a021ee805e353224b557b565 add VFP neon optimisation
03130ec51fbdc4c444cfcb9c70f4469f9f467387 Add customised makefile
a7bc9b38a6cd76703ead47b8c2a1aaf79568641e Change some debug options, add optimization options
ce49a86a24e64a7f8083e7cef85db420bbcb1004 Initial source dump from Samsung GT-N7100_HK_Opensource

Now we need to provide the range of commits over which we want patches to be generated, also specify the output directory

git format-patch -M -C --output-directory /tmp/patches db31b055b9096f8350144438901af6925b4629e3...ce49a86a24e64a7f8083e7cef85db420bbcb1004

I’ve provided the first and last commit as options.

This produces the bunch of commits:

git format-patch -M -C --output-directory /tmp/patches db31b055b9096f8350144438901af6925b4629e3...ce49a86a24e64a7f8083e7cef85db420bbcb1004
/tmp/patches/0001-Change-some-debug-options-add-optimization-options.patch
/tmp/patches/0002-Add-customised-makefile.patch
/tmp/patches/0003-add-VFP-neon-optimisation.patch
/tmp/patches/0004-little-name-tweak-to-kernel-version.patch
/tmp/patches/0005-add-support-for-customised-VM-memory-settings-and-re.patch
/tmp/patches/0006-disable-GENTLE-FAIR-SLEEPERS-enable-HRTICK.patch
/tmp/patches/0007-remove-debugging-from-MMC.patch
/tmp/patches/0008-remove-double-MALI-kconfig-entry.patch
/tmp/patches/0009-remove-mali-state-tracking-adjust-mali-dvfs-utilisat.patch
/tmp/patches/0010-fix-usb-gadget-build-error-if-debugfs-disabled.patch
/tmp/patches/0011-disable-some-multicasting-during-sleep-Credit-Andrei.patch
/tmp/patches/0012-Add-optional-FSync-disable.patch
/tmp/patches/0013-Always-mount-all-partitions-with-noatime.patch
/tmp/patches/0014-Fix-build-error-if-debugfs-disabled.patch
/tmp/patches/0015-reduce-busfrequency-increase-threshold.patch
/tmp/patches/0016-Add-1.6-1.8ghz-optional-cpu-frequency-table-1.8ghz-f.patch
/tmp/patches/0017-Sensorhub-fix-firmware-mislabelling-and-version-chec.patch
/tmp/patches/0018-lib-string-use-glibc-version-Credit-faux123.patch
/tmp/patches/0019-lib-memcopy-use-glibc-version-Credit-faux123.patch
/tmp/patches/0020-arm-remove-stale-export-of-sha_transform.patch
/tmp/patches/0021-kernel-make-an-exception-in-module-loading-to-load-p.patch
/tmp/patches/0022-arm-remove-optimized-SHA1-routines.patch
/tmp/patches/0023-lib-sha1-use-the-GIT-implementation-of-SHA-1.patch
/tmp/patches/0024-Add-optimized-ARM-RWSEM-algorithm-and-enable-in-conf.patch
/tmp/patches/0025-CRC32-slicing-by-8-algorithm.patch
/tmp/patches/0026-some-minor-crypto-changes.patch
/tmp/patches/0027-fix-a-build-error-if-debugfs-disabled.patch
/tmp/patches/0028-note2core-defconfigs-v1.04-for-non-LTE-and-LTE.patch
/tmp/patches/0029-Corrected-makefile.patch
/tmp/patches/0030-fix-to-cpu-frequency-tables.patch
/tmp/patches/0031-another-fix-to-cpu-frequency-tables.patch
/tmp/patches/0032-mach-exynos-cpuidle-exynos4-set-logging-default-to-d.patch
/tmp/patches/0033-fix-config-selection-of-1.8ghz-and-FSync.patch
/tmp/patches/0034-note2core-defconfigs-update-1.05.patch
/tmp/patches/0035-sound-soc-Sound-platform-and-WM1811-changes.patch
/tmp/patches/0036-small-cleanup-to-makefile.patch
/tmp/patches/0037-add-Triangle-Away-chainfire-support.patch
/tmp/patches/0038-sensors-update-device-sensors.patch
/tmp/patches/0039-Added-pipe-to-primary-makefile.patch
/tmp/patches/0040-CPU-unaligned-access-path.patch
/tmp/patches/0041-sched-don-t-call-task_group-many-times-in-set_task_r.patch

I did this because I found that I had weird errors while compiling the kernel for Note2, and other devs did not. Obviously I wanted to find out at what point they fixed the issue. So I what I wanted was to essentially walk over each commit and try to compile a kernel at each time

I then got the specific patch from Github. Just look at a commit, get it with suffix .patch

cat the patch see the diff level

patch -Rp1<patchfile.patch

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Remote end hung up unexpectedly, expected ok/error, helper said ‘2004�qփ��’�▒

I found this weird error while pushing my git to github!

[dz supernova-kernel]$ git push -f github master
Username:
Password:
Counting objects: 1704, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (956/956), done.
error: RPC failed; result=22, HTTP code = 411
fatal: The remote end hung up unexpectedly
Writing objects: 100% (1437/1437), 14.49 MiB, done.
Total 1437 (delta 364), reused 1099 (delta 243)
fatal: The remote end hung up unexpectedly
B��"]2 expected ok/error, helper said '2004�qփ��'�▒
$R��Ig��シ���[�0��▒PP5t4��P'[/code]

Reason: Too small http post buffer

Fix:

git config http.postBuffer 524288000[/code]

dz supernova-kernel]$ git config http.postBuffer 524288000
[dz supernova-kernel]$ git push -f github master
Username:
Password:
Counting objects: 1704, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (956/956), done.
Writing objects: 100% (1437/1437), 14.49 MiB, done.
Total 1437 (delta 364), reused 1099 (delta 243)
To http://github.com/droidzone/Supernova-Kernel.git
78dab9a..eb8e182 master -> master[/code]


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Git – Force overwrite of a remote git with a local git

I had a Google code project for my kernel which I made long ago, and wanted to overwrite it with my updated local git.

First I add the remote:

git remote add googlecode https://code.google.com/p/supernovakernel/[/code]

Then I force a push:

git push -f googlecode master[/code]

 

If I do a normal push, this was the error:

git push googlecode master
To https://code.google.com/p/supernovakernel/
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://code.google.com/p/supernovakernel/'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.[/code]


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Git – Removing the last commit

If you have committed junk but not pushed,

git reset --soft HEAD~1[/code]

HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. --soft option will delete the commit but it will leave all your changed files "Changes to be committed", as git status would put it.

If you want to get rid of any changes to tracked files in the working tree since the commit before head use --hard instead.

Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,

git revert HEAD[/code]

This will create a new commit that reverses everything introduced by the accidental commit.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Git – Rollback to last commit

“Reset the working tree to the last commit”

git reset --hard HEAD^  [/code]
"Clean unknown files from the working tree"

git clean[/code]

see - http://jonas.nitro.dk/git/quick-reference.html


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.