How to delete all local files blocking you pull, unstash and merge

git clean -n
git clean -f

First -n will dry run to check and list files can be delted. While -f will forcely to delete local files

hall-of-frame by commit numbers

git shortlog -s | sort -n -r

In short, shotlog will group and list all commits by author. By default, it will list each commits by author, while -s will only show the number of commit.

Or you can use even a simpler version to sort authers by commit number

git shortlog -s -n

How to to list of what branch for a given commit

$ git log --author todd --grep e2e
$ git name-rev 78a4c4c340de70c726844e97233c58fa4738fea9

78a4c4c340de70c726844e97233c58fa4738fea9 remotes/origin/feature/term-deposit-protractors~1

git log tips

There are various parameters calling git log

  • git log –oneline
  • git log –stat To show numer of lines added or remvoed
  • git log -p OR git log –patch To show file changes contents
  • git log –graph –oneline
  • git log -S”Search_Keyworkd” –oneline
  • git log – file1.java file2.kt
  • git log –grep=”JIRA-123”
  • git log –author=”Tom|Jerry”
  • git log –after=”yesterday”
  • git log -3 to list last 3 commits

git show

When the show method is used, it displays all the default information but for only one commit. When a commit SHA is not specified the latest commit is displayed and the output is the same as that displayed by the patch -p command. git show

To list changed files and also changes number of lines

git show --stat

To search keywords in js files only

$ find . -name '*.js' | xargs grep -r 'SearchKeywords'

One line command to add and commit file

git status --short | awk '{split($0, a);print a[2]}' | xargs git add && git commit -m 'summit status'

to show files commited but not pushed

git diff --stat --cached origin/feature/BRANCH_NAME

to view file content changed

git show PATH/FILE.sql

One line to fetch, checkout newly created branch

git fetch && git for-each-ref | grep 'AO-106'  | awk '{split($0,a);print a[3]}' | awk "{split($0,a, '/');print a[-1]}"

To get changed files NOT contains keyword

$ git status | grep -v "node_"

-v is for reverse

Cherry picking

Cherry picking in Git is designed to apply some commit from one branch into another branch. It can be done if you eg. made a mistake and committed a change into wrong branch, but do not want to merge the whole branch. You can just eg. revert the commit and cherry-pick it on another branch.

To use it, you just need git cherry-pick hash, where hash is a commit hash from other branch.

Difference among git merge and git rebase

TL;NR Git rebase and merge both integrate changes from one branch into another. Where they differ is how it’s done. Git rebase moves a feature branch into a master. Git merge adds a new commit, preserving the history.

Rebase

Git rebase compresses all the changes into a single “patch.” Then it integrates the patch onto the target branch. Unlike merging, rebasing flattens history. It transfers the completed work from one branch to another. In the process, unwanted history is eliminated.

Advocates of Git rebase like it because it simplifies their review process.

Merge

It takes the contents of a source branch and integrates it with a target branch.

Differences among Git and subversion

The differences between git and other source control (like subversion) is Git have to merge conflict before upload to server, while subversion will merge conflicts at server side

following lages are searchable in google

Errors

WARN No layout: index.html

Following errors when run hexo g

Unhandled rejection Error: ENOENT: no such file or directory, open '/Users/todzhang/dev/git/blogSrc/themes/next/layout/_scripts/schemes/.swig'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at Object.ret.load (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/swig/lib/loaders/filesystem.js:55:15)
    at compileFile (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/swig/lib/swig.js:695:31)
    at Object.eval [as tpl] (eval at <anonymous> (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/swig/lib/swig.js:498:13), <anonymous>:338:18)
    at compiled [as _compiledSync] (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/swig/lib/swig.js:619:18)
    at tryCatcher (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/bluebird/js/release/util.js:16:23)
    at null._compiled (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/bluebird/js/release/method.js:15:34)
    at View.render (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/lib/theme/view.js:29:15)
    at /Users/todzhang/dev/git/blogSrc/node_modules/hexo/lib/hexo/index.js:387:25
    at tryCatcher (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/bluebird/js/release/util.js:16:23)
    at /Users/todzhang/dev/git/blogSrc/node_modules/hexo/node_modules/bluebird/js/release/method.js:15:34
    at RouteStream._read (/Users/todzhang/dev/git/blogSrc/node_modules/hexo/lib/hexo/router.js:134:3)
    at RouteStream.Readable.read (_stream_readable.js:336:10)
    at resume_ (_stream_readable.js:733:12)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)

Solution:

That’s because one extra space required after semi colon in _config.yml of Next, as following config

# Duoshuo ShortName
duoshuo_shortname: cloudsdocker

branch diverged

~|master ⇒ git status On branch master Your branch and ‘origin/master’ have diverged, and have 1 and 6 different commits each, respectively. (use “git pull” to merge the remote branch into yours)

The git pull command provides a shorthand way to fetch from origin and rebase local work on it:

$ git pull –rebase

To checkout and rebase master to current branch

git rebase HEAD master

undo a commit

git revert <commit hash>

Your branch is ahead of ‘origin/master’ by xx commits

Go to Intellij, select git view and chose log, then select previous version before those xx commits, then chose Reset current branch to here and with hard as option.

Git commit

List files of a given commit

git show commit_id

git show --pretty="" --name-only bd61ad98    

Updates were rejected because the tip of your current branch is behind

git push –set-upstream origin master To https://github.com/CloudsDocker/cloudsdocker.github.io.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to ‘https://github.com/CloudsDocker/cloudsdocker.github.io.git’ hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: ‘git pull …’) before pushing again. hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

todds-MacBook-Pro:cloudsdocker.github.io todzhang$ git push To https://github.com/CloudsDocker/cloudsdocker.github.io.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to ‘https://github.com/CloudsDocker/cloudsdocker.github.io.git’ hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: ‘git pull …’) before pushing again. hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details. todds-MacBook-Pro:cloudsdocker.github.io todzhang$ git pull fatal: refusing to merge unrelated histories

Updated: