2020年5月14日 星期四

Frequently used git command

Details
There are some cases I need to use some specific git commands for some special purposes, like 
  • Undoing git merge which haven't be pushed
    • git reflog (Get the commit desired to return)
    • git reset --hard sha

  • Cherry-picking specific file changes from 1 commit to another
    • git checkout <branch or sha of commit> -- filename

  • Retrieve just 1 file from specific branch
    • git checkout experiment -- app.js

  • Show content changes which have been staged
    • git diff --cached

  • Show the diff of the same file between different commits of the same branch
    • git diff HEAD^^ HEAD someFile (Show differences of someFile 2 commits before HEAD)

  • Show file changes on specific commit (without diff information)
    • git show --pretty="" --name-only {commit-sha}

  • Show commits differences between 2 branches since branch created (file list)
    • git log --oneline master..myBranch (Show changes since master branch)
    • git log --oneline --no-merges master..myBranch (Show changes since master branch skipping merge commits)

  • Get a list of branches created ordered with create date
    • git branch --sort=-committerdate  # DESC
    • git branch --sort=committerdate  # ASC

  • Commit with standard input
    • echo -e 'Update version number to v1.6.72.0\n\nfrom v1.6.70.0 to v1.6.72.0' | git commit /home/jacky/Documents/gitproj/p2_controller/docker/docker-compose-prod.yml /home/jacky/Documents/gitproj/p2_controller/docker/docker-compose-prod-upgrade.yml /home/jacky/Documents/gitproj/p2_controller/p2_controller/static_data/VERSION -F -
References

沒有留言:

張貼留言