Thursday, July 14, 2016

install Java - JDK on Ubuntu

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

To set up the Java 7 environment variables such as JAVA_HOME and PATH,
sudo apt-get install oracle-java7-set-default


sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Monday, July 11, 2016

install korean on ubuntu

sudo apt-get install ibus-hangul
reboot
run "ibus-setup"
input method -> add 'Korean - Hangul'
open 'System Settings'
Text Entry
add "Korean - Hangul"

Tuesday, July 5, 2016

Linux kernel perf

root@OpenWrt:/# perf record -f -g -a
  Error: unknown switch `f'

 usage: perf record [<options>] [<command>]
    or: perf record [<options>] -- <command> [<options>]

    -e, --event <event>   event selector. use 'perf list' to list available events
        --filter <filter>
                          event filter
    -p, --pid <pid>       record events on existing process id
    -t, --tid <tid>       record events on existing thread id
    -r, --realtime <n>    collect data with this RT SCHED_FIFO priority
        --no-buffering    collect data without buffering
    -R, --raw-samples     collect raw sample records from all opened counters
    -a, --all-cpus        system-wide collection from all CPUs
    -C, --cpu <cpu>       list of cpus to monitor
    -c, --count <n>       event period to sample
    -o, --output <file>   output file name
    -i, --no-inherit      child tasks do not inherit counters
    -F, --freq <n>        profile at this frequency
    -m, --mmap-pages <pages>
                          number of mmap data pages
        --group           put the counters into a counter group
    -g                    enables call-graph recording
        --call-graph <mode[,dump_size]>
                          setup and enables call-graph (stack chain/backtrace) recording: fp
    -v, --verbose         be more verbose (show counter open errors, etc)
    -q, --quiet           don't print any message
    -s, --stat            per thread counts
    -d, --data            Sample addresses
    -T, --timestamp       Sample timestamps
    -P, --period          Sample period
    -n, --no-samples      don't sample
    -N, --no-buildid-cache
                          do not update the buildid cache
    -B, --no-buildid      do not collect buildids in perf.data
    -G, --cgroup <name>   monitor event in cgroup name only
    -D, --delay <n>       ms to wait before starting measurement after program start
    -u, --uid <user>      user to profile
    -b, --branch-any      sample any taken branches
    -j, --branch-filter <branch filter mask>
                          branch stack filter modes
    -W, --weight          sample by weight (on special events only)
        --transaction     sample transaction flags (special events only)
        --per-thread      use per-thread mmaps

root@OpenWrt:/#


perf

You can also use the standard Linux perf tool:
ps aux | grep chromium to find a particular browser/renderer/gpu process
perf record -f -g -p <pid> to capture that process
perf report for the profile output
perf annotate "<fully qualified function name>" for assembly language and (very approximate?) per-instruction cycle counts
By default this saves "perf.data" in the current working directory, which can be renamed.
perf report may be able to run on older data, but perf annotate will be inaccurate if you've since rebuilt the executable.

==========================================================================
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
  784     2 root     SW       0   0%   3% [kworker/1:3]
   14     2 root     SW       0   0%   1% [ksoftirqd/1]
 
 
perf record -g -a -p 3

perf report -i xxx.data

perf annotate -vvv memcpy > /dev/null

X:\build_dir\target-arm_cortex-a7_uClibc-0.9.33.2_eabi\linux\vmlinux.debug

It also now looks at /sys/kernel/notes, gets the build-id, and looks up in the build-id cache.

================================== add debugging symbol to modules ==============================
Compile packages with debugging info
sdk/config/Config-build.in
config DEBUG
bool
prompt "Compile packages with debugging info"
default n
help
 Adds -g3 to the CFLAGS
    ->> CONFIG_DEBUG=y
->> CONFIG_NO_STRIP=y
->> CONFIG_USE_SSTRIP=y

*** CONFIG_DEBUG=y
sdk/rules.mk
TARGET_CFLAGS:=$(TARGET_OPTIMIZATION)$(if $(CONFIG_DEBUG), -g3) $(EXTRA_OPTIMIZATION)

backport/mac80211/Makefile
include $(TOPDIR)/rules.mk
***** working *****
MAKE_OPTS:= -C "$(PKG_BUILD_DIR)" \
EXTRA_CFLAGS="-g3 -I$(PKG_BUILD_DIR)/include -I$(STAGING_DIR)/usr/include/drv" \

================================== remove strip command ===========================================
*** CONFIG_NO_STRIP
sdk/rules.mk
# strip an entire directory
ifneq ($(CONFIG_NO_STRIP),)
 RSTRIP:=:
 STRIP:=:
else
 ifneq ($(CONFIG_USE_STRIP),)
STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS))
 else
ifneq ($(CONFIG_USE_SSTRIP),)
 STRIP:=$(STAGING_DIR_HOST)/bin/sstrip
endif
 endif
 RSTRIP:= \
export CROSS="$(TARGET_CROSS)" \
$(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \
$(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \
NM="$(TARGET_CROSS)nm" \
STRIP="$(STRIP)" \
STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \
$(SCRIPT_DIR)/rstrip.sh
endif
***** working *****
sdk/src/linux/Makefile
KBUILD_LDFLAGS_MODULE = -T $(srctree)/scripts/module-common.lds $(if $(CONFIG_PROFILING),,-s)
-->>
KBUILD_LDFLAGS_MODULE = -T $(srctree)/scripts/module-common.lds

*** how to define CONFIG_XXX
backport/mac80211/Makefile
export CONFIG_NO_STRIP:=1
export CONFIG_NO_STRIP:=y
export CONFIG_DEBUG:=y
include $(TOPDIR)/rules.mk

================================== compiling with CONFIG options ===========================================
make package/backport/mac80211/{clean,compile} package/index V=s CONFIG_NO_STRIP=y CONFIG_DEBUG=y


================================== driver modules to be used ================================================
build_dir/target_xxxx/linux/backports/net/mac80211/mac80211.ko


================================== vmlinux to be used ================================================
sdk/build_dir/target_xxxx/linux/vmlinux.debug

================================= location to copy driver debug modules =========================================
/lib/modules/3.14.43/kernel/net/wireless/cfg80211.ko
/lib/modules/3.14.43/kernel/net/wireless/mac80211.ko
*** can be symbolic link

================================= perf command =========================================
perf record -g -a -p 3

perf report -i xxx.data

================================= perf command on x86=========================================
perf annotate -k vmlinux -i perf.tcp.dl.data --objdump=/home/sdk/build_dir/toolchain-arm_cortex-a7_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/binutils-2.22/binutils/objdump


========================== perf annotate verbose ========================
symbol__annotate: filename=/root/.debug/.build-id/b5/15361e474796af29de9992b76a97cffb39b2a7, sym=__libc_disable_asynccancel, start=0x7fedc39d1d10, end=0x7fedc39d1d68
annotating [0x9d8aa0] /lib/x86_64-linux-gnu/libc-2.19.so : [0x108ec20]     __libc_disable_asynccancel
Executing: objdump  --start-address=0x0000000000108d10 --stop-address=0x0000000000108d69 -d --no-show-raw -S -C /root/.debug/.build-id/b5/15361e474796af29de9992b76a97cffb39b2a7 2>/dev/null|grep -v /root/.debug/.build-id/b5/15361e474796af29de9992b76a97cffb39b2a7|expand


    --symfs=<directory>
        Look for files with symbols relative to this directory.

========================== perf annotate -- locaion to copy modules ??? ========================
rootfs ./debug/modules/mac80211.ko

linux network data flow

sar / mpstat commands (irq, interrupts, proc/interrupts)

sar -P ALL 1 3

The interrupt rate can be measured using the 'sar' tool, like:

"sar -I <interrupt_number> 1"

# sar --help
Usage: sar [ options ] [ <interval> [ <count> ] ]
Options are:
[ -A ] [ -B ] [ -b ] [ -C ] [ -d ] [ -F ] [ -H ] [ -h ] [ -p ] [ -q ] [ -R ]
[ -r ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -V ] [ -v ] [ -W ] [ -w ] [ -y ]
[ -I { <int> [,...] | SUM | ALL | XALL } ] [ -P { <cpu> [,...] | ALL } ]
[ -m { <keyword> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ]
[ -j { ID | LABEL | PATH | UUID | ... } ]
[ -f [ <filename> ] | -o [ <filename> ] | -[0-9]+ ]
[ -i <interval> ] [ -s [ <hh:mm:ss> ] ] [ -e [ <hh:mm:ss> ] ]


# cat /proc/interrupts

root@OpenWrt:/proc# sar -I 68 -I 90 1
Linux 3.14.0 (OpenWrt)  01/07/15        _armv7l_        (2 CPU)

18:10:08         INTR    intr/s
18:10:09           68    992.00
18:10:09           90      0.00

18:10:09         INTR    intr/s
18:10:10           68   1026.00
18:10:10           90      0.00

root@OpenWrt:/proc# sar -I 68 1
Linux 3.14.0 (OpenWrt)  01/07/15        _armv7l_        (2 CPU)

18:01:59         INTR    intr/s
18:02:00           68   2111.00
18:02:01           68   1657.00
18:02:02           68   1213.00
18:02:03           68    819.00
18:02:04           68    747.00
18:02:05           68    836.00
18:02:06           68    678.00
18:02:07           68    708.00
18:02:08           68   1346.00
18:02:09           68    768.00
18:02:10           68    613.00
18:02:11           68   1399.00
^C
18:02:11           68    993.55
Average:           68   1072.54

root@OpenWrt:/proc# sar -I SUM 68
Linux 3.14.0 (OpenWrt)  01/07/15        _armv7l_        (2 CPU)
^C

18:18:02         INTR    intr/s
18:18:03          sum   1721.82
Average:          sum   1721.82

============= net socket profile =======================

sar -n DEV 2 2
Network statistics
$ sar -n IP 2 2
$ sar -n TCP 2 2
$ sar -n SOCK 2 2


================================================

root@OpenWrt:/# mpstat -P ALL 1 5
Linux 3.14.77 (OpenWrt) 10/18/18 _armv7l_ (4 CPU)

04:08:09     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:08:10     all    2.32    0.00    0.26    0.00    0.26    2.58    0.00    0.00    0.00   94.59
04:08:10       0    5.10    0.00    1.02    0.00    1.02    9.18    0.00    0.00    0.00   83.67
04:08:10       1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:08:10       2    2.06    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   97.94
04:08:10       3    2.13    0.00    0.00    0.00    0.00    1.06    0.00    0.00    0.00   96.81

================================================


root@OpenWrt:/# sar -P ALL 1 3
Linux 3.14.77 (OpenWrt) 10/18/18 _armv7l_ (4 CPU)

04:08:23        CPU     %user     %nice   %system   %iowait    %steal     %idle
04:08:24        all      1.77      0.00      2.78      0.00      0.00     95.45
04:08:24          0      3.03      0.00     10.10      0.00      0.00     86.87
04:08:24          1      0.00      0.00      1.02      0.00      0.00     98.98
04:08:24          2      1.01      0.00      0.00      0.00      0.00     98.99
04:08:24          3      3.00      0.00      0.00      0.00      0.00     97.00

objdump command

objdump -s -S -D ~/build_dir/target-arm_cortex-a7_uClibc-0.9.33.2_eabi/linux/backports/net/mac80211/mac80211.o 2>&1 | tee ~/mac80211.txt

Usage: arm-openwrt-linux-objdump <option(s)> <file(s)>
 Display information from object <file(s)>.
 At least one of the following switches must be given:
  -a, --archive-headers    Display archive header information
  -f, --file-headers       Display the contents of the overall file header
  -p, --private-headers    Display object format specific file header contents
  -P, --private=OPT,OPT... Display object format specific contents
  -h, --[section-]headers  Display the contents of the section headers
  -x, --all-headers        Display the contents of all headers
  -d, --disassemble        Display assembler contents of executable sections
  -D, --disassemble-all    Display assembler contents of all sections
  -S, --source             Intermix source code with disassembly
  -s, --full-contents      Display the full contents of all sections requested
  -g, --debugging          Display debug information in object file
  -e, --debugging-tags     Display debug information using ctags style
  -G, --stabs              Display (in raw form) any STABS info in the file
  -W[lLiaprmfFsoRt] or
  --dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,
          =frames-interp,=str,=loc,=Ranges,=pubtypes,
          =gdb_index,=trace_info,=trace_abbrev,=trace_aranges]
                           Display DWARF info in the file
  -t, --syms               Display the contents of the symbol table(s)
  -T, --dynamic-syms       Display the contents of the dynamic symbol table
  -r, --reloc              Display the relocation entries in the file
  -R, --dynamic-reloc      Display the dynamic relocation entries in the file
  @<file>                  Read options from <file>
  -v, --version            Display this program's version number
  -i, --info               List object formats and architectures supported
  -H, --help               Display this information

GDB example

GNU Debugger
Please look upstream for multilingual instructions and manuals, like e.g. here: http://sourceware.org/gdb/current/onlinedocs/gdb/

Compiling Tools
in menuconfig enable gdb
Advanced configuration options (for developers) → Toolchain Options → Build gdb
and gdbserver
Development → gdbserver

Add debugging to a package
Add CFLAGS to the package Makefile and recompile it.
TARGET_CFLAGS += -ggdb3
backports/Makefile
- MAKE_OPTS:
- EXTRA_CFLAGS=" -ggdb3" /* DOES NOT WORK */

Alternatively recompile the package with CONFIG_DEBUG set
make package/busybox/{clean,compile} V=99 CONFIG_DEBUG=y
make package/backports/{clean,compile} V=99 CONFIG_DEBUG=y
make package/mac80211/{clean,compile} package/index CONFIG_DEBUG=y

Or you can enable debug info in menuconfig
Global build settings > Compile packages with debugging info

Remove Strip option (-s) from LD Flags
/linux/Makefile
KBUILD_LDFLAGS_MODULE = -T $(srctree)/scripts/module-common.lds $(if $(CONFIG_PROFILING),,-s)

/build_dir/target-arm_cortex-a7_uClibc-0.9.33.2_eabi/linux/linux-3.14/Makefile
/* This Makefile is not a copy of src/linux/Makefile */

Starting GNU Debugger
Start gdbserver on target (router)
gdbserver :9000 /bin/ping example.org

Start gdb on host (in compiling tree)
./scripts/remote-gdb 192.168.1.1:9000 ./build_dir/target-*/busybox-*/busybox
now you have a gdb shell. Set breakpoints, start program, backtrace etc.

(gdb) b source-file.c:123
(gdb) c
(gdb) bt

/build_dir/toolchain-arm_cortex-a7_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/binutils-2.22/binutils$

:~/build_dir/toolchain-arm_cortex-a7_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/binutils-2.22/binutils$ objdump -S ~/build_dir/target-arm_cortex-a7_uClibc-0.9.33.2_eabi/linux/backports/net/mac80211/mac80211.o 2>&1 | tee ~/works/temp/mac80211.txt

objdump -d shows instructions
objdump –S net/mac80211/rx.o
http://wiki.openwrt.org/doc/devel/gdb


~/works/staging_dir/toolchain-arm_cortex-a7_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin$ arm-openwrt-linux-gdb ~/build_dir/target-arm_cortex-a7_uClibc-0.9.33.2_eabi/linux/backports/net/mac80211/mac80211.ko
$ pwd
/staging_dir/toolchain-arm_v7-a_gcc-4.6-linaro_uClibc-0.9.33.2_eabi/bin

$ ./arm-openwrt-linux-gdb ~/build_dir/linux/backports/net/mac80211/mac80211.ko
GNU gdb (Linaro GDB) 7.2-2011.03-0
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-openwrt-linux-uclibcgnueabi".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /build_dir/linux/backports/net/mac80211/mac80211.ko...done.
(gdb) disas /m ieee80211_sta_ps_transition

(gdb) l *ieee80211_sta_ps_transition
0x1cab8 is in ieee80211_sta_ps_transition (/build_dir/linux/backports/net/mac80211/rx.c:1264).
1259            clear_sta_flag(sta, WLAN_STA_PS_STA);
1260            ieee80211_sta_ps_deliver_wakeup(sta);
1261    }
1262
1263    int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1264    {
1265            struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1266            bool in_ps;
1267
1268            WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));

========================================================================
** gdb
http://wiki.openwrt.org/doc/devel/gdb
========================================================================

Linux patch commit message reference


You are still talking only about the low level code and about low
level symptoms, while in contrast to that the primary question with
_any_ change to the kernel is always:

WHY ARE WE CHANGING THE KERNEL, WHAT BAD HIGH LEVEL BEHAVIOR CAN A
USER OBSERVE IF THE BUG IS NOT FIXED?

Your descriptions totally ignore the high level effects of the bug on
the system and on users of the machine, and you fail to describe them
properly. You totally concentrate on the low level: your descriptions
are missing the forest from all the trees.

That makes 90% of your patch descriptions useless.

In fact, 90% of your patches had that deficiency and had it for the
past 4 years, non-stop, and maintainers were complaining to you about
that, non-stop as well. Do you think maintainers enjoy complaining
about deficiencies? Do you wonder why maintainers were forced to
simply stop looking at any complex series from yours after you refused
to change?

> will refresh the patchset.

So let me try this again, one very last time.

That sentence demonstrates your problem: it's not a 'refresh' your
patches need, but a 'hard reboot', a totally new viewpoint that
concentrates on what matters: that zooms out of the small details of
the patch!

For any serious change to the Linux kernel, analyzing small details is
fine and required as well, AFTER the high level has been discussed
properly:

- What happened, what high level concern motivates you to change the
Linux kernel?

And no, starting a changelog with:

commit e6023367d779 ("x86, kaslr: Prevent .bss from
overlaping initrd") introduced one run_size for kaslr.

is not 'high level' in any way, it talks about code in the
first sentence! Talking about code, not talking about high
level concerns is a BUG().

- What was the previous (often bad) high level behavior of the
kernel?

And no, 'KASLR will not find a proper area' is NOT a high level
description, it's a very low level description! Not discussing
high level behavior of the kernel in a changelog is a BUG().

- What new high level behavior do we want to happen instead?

And no, saying that 'KASLR should be passed init_size instead
of run_size' is not a description of desired new high level
behavior! Not discussing the desired high level behavior of the
kernel in a changelog is a BUG().

- What was the high level design of the old code, was that design
fine, should it be changed, and if yes, in what way?

Note that we describe the high level design even if we don't
change it, partly to give context to the reader, partly to
prove that you know what you are doing, to build trust in your
patch! Not discussing the old (and new) design of that area of
the kernel is a BUG().

and only then do we:

- Describe the old implementation, and describe how the new
implementation works in all that context.

Here is where 99.9% of your existing changelogs fit in.
Put differently: your changelogs are missing the first 3
essential components of a changelog.

And note, mentioning 'run_size' in a low level description is
fine. Mentioning it in a high level description is a BUG():
that is why Boris was trying to change your changelogs into
spoken English, to recover some of that missing high level
context. Maintainers like Boris should not be forced to do
that, you are supposed to offer this with any significant
patch, as a passport to prove that your changes to the code are
worth looking at.

And yes, we do it in that order. Take a look at a recent single line
change Linus made in 53da3bc2ba9e48, attached to this mail.

Check how the changelog is structured: it discusses high level
concepts first. It's a _ONE LINER FIX_ from Linus, yet it's spread
over 8 paragraphs and 50 lines, because the change justified that kind
of description.

And observe the moment when Linus, in his 8 paragraphs, 50 lines
description starts talking about low level implementational details,
when he mentions lines of code, function names, such as
do_numa_page(), 'pte_write()' or 'pte_dirty()'.

He doesnt!

It's not needed for a one-liner most of the time: but the high level
concepts around that code are very much necessary to convey.

Now contrast that with your changelogs: your changelogs are stock full
of non-English phrases resembling code more than a fluid description,
they are stock full of low level details, mentioning of function
names, variables and fields with no high level context conveyed
whatsoever.

Let me try to put it to you in a way that might come across: when I
run maintainer code over your changelogs it runs into an instant BUG()
most of the time, forcing me to drop your patches.

High level discussion of old behavior, new behavior, old design and
new design isn't just some detail to be slapped on a change after the
fact, this is a serious and required technological aspect of the Linux
kernel, and 90% of your patches are buggy in that respect.

In fact, I noticed that both your descriptions and your followups to
them are totally lacking the high level viewpoint!

Either you:

- refuse to think in high level concepts when you are writing
patches, in which case we need to keep your patches away from
the Linux kernel,

- or you are unwilling to document such high level thinking
processes, in which case we need to keep your patches away from
the Linux kernel as well.

If your appoach to writing kernel patches does not change then I will
be forced to take action, currently you are this -->.<-- close to
being filtered out from my default inbox for your total refusal to
change the technology of how you are writing patches.

Thanks,

Ingo

[ Sample 'good' changelog from Linus: ]



Friday, July 1, 2016

git tips


* git cherry-pick  -- a range of commit
git cherry-pick ebe6942^..905e279


4. Author submits change commit to Gerrit for review
4.1 submit a change (a commit)
4.1.1 before submitting your patch run git rebase to avoid conflict
$ git pull --rebase
4.1.2 easy way if you're under SDK
$ repo upload
4.1.3 another way using git push
$ git push ssh://git.ebmajor.com:1234/oss/system/feeds/branch_name HEAD:refs/for/repo_branch_name
$ git push ssh://git.ebmajor.com:1234/oss/system/feeds/branch_name <local_repo_branch_name>:refs/for/repo_branch_name
ssh://git.ebmajor.com:1234 it's common part
oss/system/feeds/branch_name project name.
project names can be found here
https://git-poh-scl.ebmajor.com/cgit.cgi/?s=name
HEAD:refs/for/repo_branch_name branch name, "repo_branch_name", used at repo init.
$ git push ssh://git.ebmajor.com:1234/wifi/poh-wireless HEAD:refs/for/repo_branch_name
ssh://git.ebmajor.com:1234 it's common part
wifi/poh-wireless project name.
project names can be found here
https://git-poh-scl.ebmajor.com/cgit.cgi/?s=name
HEAD:refs/for/repo_branch_name branch name, "repo_branch_name", used at repo init.
4.1-1 submit single change
$ git push ssh://git.ebmajor.com:1234/oss/system/feeds/branch_name <commit SHA1>:refs/for/repo_branch_name

git log --oneline --pretty=format:"%ad - %an: %s" --after="2019-06-01" --until="2019-06-30" --author="Peter"

6. Extra commands good to know
* make changes on top of current patch
$ git commit --amend
* display branch's history and has lots of options
$ git log
$ git log --oneline //display in short
$ git log --author="author name" //search by author
$ git log --grep="strings" //search by string
* display a file's history
$ git log xxx.c
* display the file's change history line by line
$ git blame xxx.c
* delete untracked files and directory
$ git clean -df
$ git clean -dfx
$ git clean -dffx
* save changes temporarily and clean current branch
$ git stash save --keep-index
* re-store saved changes
$ git stash pop
* delete everything that not saved as a commit
$ git reset --hard HEAD
* delete very top commit
$ git reset --hard HEAD~
* delete top third commit
$ git reset --hard HEAD~3
* rollback your commit
$ git revert sha1
* display the history of git commands
$ git reflog
* make a git branch clean (go back) to specific git command history
$ git reflog // look for sha1 to go back
$ git reset --hard sha1
* remove a branch that does not need any more.
$ git branch -D "branch name"
* remove the branch that I'm on currently
$ repo abandon "branch name"
or
$ git checkout HEAD^
$ git branch -D "branch name"
* remove all the branches that local patches are already merged
$ repo prune
* display all the branches including remote repositories
$ git branch -a
* ???
$ git rev-parse
* sync current branch to <branch name>
$ git reset --hard <branch name>
* sync to specific branch and specific sha1
$ git rebase <branch name or commit ID>
$ git rebase --onto master 169a6
* to sync to a particular Release Image
repo init -b refs/tags/LINUX_RELEASE_repo_branch_name_1.01 -u ssh://git.ebmajor.com:1234/releases/manifest/stak.git -m versioned.xml
* create a branch on tag
$ git tag -l
$ git checkout -b local_branch tags/tagname
* adding author manually
$ git commit --amend --author 'First Last <user@ebmajor.org>'
* generate a patch file from a commit
$ git format-patch HEAD^
$ git format-patch -1 <sha1>
$ git format-patch --start-number 41 -1 <sha1>
* cherry pick single commit from another branch
$ git cherry-pick <sha1>
* cherry pick multiple commits from another branch
$ git checkout -b newbranch 62ecb3 (sha1 on local-branch)
$ git rebase --onto ath-next 76cada^
* amend commit of old patches
$ git rebase -i HEAD~5 (up to the commit we want to edit)
    This command will pop-up dialog like below.
"pick e7e285a UPSTREAM: :
pick 685c90f UPSTREAM:
pick e0f9f10 UPSTREAM:
pick 19f5562 UPSTREAM:
pick a94c23a FROMLIST:
# Rebase cfb53a9..a94c23a onto cfb53a9"
Replace "pick" with "reword" before each commit message you want to change.
"     reword e7e285a UPSTREAM:
reword 685c90f UPSTREAM:
Save and close the commit list file.
In each resulting commit file, type the new commit message, save the file, and close it.

* man git-format-patch

* add git user on local directory only (without "--global")
git config user.name "Your Name"
git config user.email "you@example.com"

* reset author/committer
git config --global user.email "xxx@xxx.com"
git commit --amend --reset-author

* show changes before sha1 (git blame prior to sha1)
git blame sha1^ -- src/options.cpp (git blame fe25b6d^)

* git logs on removed file
git log --all --full-history -- "**/thisfile.*" git log --all --full-history -- <path-to-file>

* git add removed file
git add -u .

* merge specific files/folders from different git repository
* mac80211_plus_ebmajor: mac80211 branch to merge ebmajor (mac80211 based)
* ebmajor_to_be_merged: ebmajor branch from ebmajor.git to be merged to mac80211
1. add another git repository to current working git repository (add ath10k git to mac80211 git)
mac80211$ git remote add ebmajor git://git.kernel.org/pub/scm/linux/kernel/git/ebmajor.git
mac80211$ git remote add ebmajor ~/works/ebmajor
2. apply the remote git repository
mac80211$ git remote update ebmajor
3. check remote git branch if it merged to working repository
mac80211$ git branch -a
4. create local branch from ebmajor git which to be merged
mac80211$ git checkout -b ebmajor_to_be_merged remotes/ebmajor/ebmajor_to_be_merged
4. create a local branch based on mac80211 git (create branch from mac80211 git)
mac80211$ git checkout -b mac80211_plus_ebmajor remotes/origin/master
5. checkout target remote branch with folder/file name specific (checkout ebmajor git on mac80211 branch)
mac80211$ git checkout ebmajor_to_be_merged -- drivers/net/wireless/ebmajor/
* it gets ebmajor files from ebmajor git and overwrites ebmajor files on mac80211 git
6. run git commit
git commit -s
7. update remote branch (ebmajor_merge_to_mac)
$git remote update

* repo sync verbose mode
$repo --trace sync

* repo sync quickly
“-c” flag. repo will only download the revision (branch) that is specified in the manifest, not all the branches that are on the remote server.
$repo sync -c

git checkout mac80211_master
git read-tree --prefix=ebmajor/ -u ebmajor_master:drivers/net/wireless/ebmajor/

* Add gerrit review URL

* git bisect
git bisect start net/mac80211/ drivers/net/wireless/ebmajor/ ; git bisect bad ; git bisect good v4.6

* remove cached file
git rm --cached xxx

* remove local branches no longer on remote
git remote prune origin

* add hooks for Change-Id
cd project_folder (which .git folder exist)
scp -p -P 29418 peter.oh@ebmajor.com:hooks/commit-msg .git/hooks/

* git log lines
git log -L 15,23:filename.txt
means "trace the evolution of lines 15 to 23 in the file named filename.txt".

* git log to removed lines
git log -c -S'missingtext' /path/to/file

git log -S <string> path/to/file
git log --cc -S'missingtext' /path/to/file

* git clone with submodule
git submodule update --init --recursive

* do repo sync with submodule download
1. in manifest, specify the attribute sync-s="true"
for example <default sync-s="true"/> to apply to all projects
or for a specific project, <project sync-s="true"/>
2. repo sync --fetch-submodules

* force update for 2nd commit
git push github +HEAD

* git log from specific date
git log --after="2013-11-12 00:00" --before="2013-11-13 00:00"
git log --since="2014-02-12T16:36:00-07:00"
git log --after="2014-02-12T16:36:00-07:00"
git log --before="2014-02-12T16:36:00-07:00"
git log --since="1 month ago"
git log --since="2 weeks 3 days 2 hours 30 minutes 59 seconds ago"
git log --date=local --after="2014-02-12T16:36:00-07:00"

* merge 2 different branches on different remotes
------
step 1 - check in existing codes
------

packages/qca-rfs$ git checkout -b github_master remotes/origin/release/collard_cc_cs

peter@peter-linux-dell:~/works/src/qsdk_packages/qca-rfs$ cat .git/config
[remote "origin"]
url = https://source.codeaurora.org/quic/qsdk/oss/lklm/qca-rfs
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "github"]
url = git@github.com:ebmajor/qca-rfs.git
fetch = +refs/heads/*:refs/remotes/github/*
[branch "github_master"]
remote = origin
merge = refs/heads/release/collard_cc_cs

packages/qca-rfs$ git push -u github github_master

------
step 2 - merge branch on different remote
------

git clone git@github.com:ebmajor/qca-rfs.git

git remote add caf https://source.codeaurora.org/quic/qsdk/oss/lklm/qca-rfs

git checkout github_master

git pull caf release/dandelion_ath10k //pull "release/dandelion_ath10k" from caf to "github_master"
// don't need "fetch src"

github/qca-rfs$ cat .git/config
[remote "origin"]
url = git@github.com:ebmajor/qca-rfs.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "github_master"]
remote = origin
merge = refs/heads/github_master
[remote "caf"]
url = https://source.codeaurora.org/quic/qsdk/oss/lklm/qca-rfs
fetch = +refs/heads/*:refs/remotes/caf/*

git push -u origin HEAD (or git push -u origin github_master)

----------
* git merge a local branch to another local branch
----------
local-branch-1 (local-branch-2 will be merged to here)
local-branch-2

1. git checkout local-branch-1
2. git merge local-branch-2
--------------

* create a new branch from local branch reference
git checkout -b poh_local_branch_from_local local_branch_org (no origin/)

=====
git merge except some commits
=====
master$ git merge maint~4
master$ git merge -s ours maint~3
master$ git merge maint

* squash multiple commits to one commit

 $ git rebase -i develop

 upstream branch should be the branch that current local branch is based on.
 If my local branch name is "peter/ipq40xx/develop" which is based on upstream "develop" (remote/origin/develop)
 then run git rebase -i develop.

$git rebase -i develop

 This will open an editor window, with a bunch of commits listed prefixed by pick.
 change all of pick to squash except the first commit.
 This tells git to keep all of those changes, but squash them into the first commit.

* git diff between branches
$ git diff branch_1..branch_2 (2 dots)
   to produce the diff between the tips of the two branches.
$git diff branch_1...branch_2 (3 dots)
   to find the diff from their common ancestor to test