• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

git-tips/tips: Most commonly used git tips and tricks.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

git-tips/tips

开源软件地址:

https://github.com/git-tips/tips

开源编程语言:

JavaScript 100.0%

开源软件介绍:

git-tips

Collection of git-tips, want to add your tips? Checkout contributing.md

English | 中文 | Русский | 한국어 | Tiếng Việt | 日本語 | नेपाली | Polski | فارسی

Tools:

P.S: All these commands are tested on git version 2.7.4 (Apple Git-66).

Everyday Git in twenty commands or so

git help everyday

Show helpful guides that come with Git

git help -g

Search change by content

git log -S'<a term in the source>'

Show changes over time for specific file

git log -p <file_name>

Remove sensitive data from history, after a push

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <path-to-your-file>' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all

Sync with remote, overwrite local changes

git fetch origin && git reset --hard origin/master && git clean -f -d

List of all files till a commit

git ls-tree --name-only -r <commit-ish>

Git reset first commit

git update-ref -d HEAD

Reset: preserve uncommitted local changes

git reset --keep <commit>

List all the conflicted files

git diff --name-only --diff-filter=U

List of all files changed in a commit

git diff-tree --no-commit-id --name-only -r <commit-ish>

Unstaged changes since last commit

git diff

Changes staged for commit

git diff --cached

Alternatives:

git diff --staged

Show both staged and unstaged changes

git diff HEAD

List all branches that are already merged into master

git branch --merged master

Quickly switch to the previous branch

git checkout -

Alternatives:

git checkout @{-1}

Remove branches that have already been merged with master

git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d

Alternatives:

git branch --merged master | grep -v '^\*\|  master' | xargs -n 1 git branch -d # will not delete master if master is not checked out

List all branches and their upstreams, as well as last commit on branch

git branch -vv

Track upstream branch

git branch -u origin/mybranch

Delete local branch

git branch -d <local_branchname>

Delete remote branch

git push origin --delete <remote_branchname>

Alternatives:

git push origin :<remote_branchname>
git branch -dr <remote/branch>

Create local tag

git tag <tag-name>

Delete local tag

git tag -d <tag-name>

Delete remote tag

git push origin :refs/tags/<tag-name>

Undo local changes with the last content in head

git checkout -- <file_name>

Revert: Undo a commit by creating a new commit

git revert <commit-ish>

Reset: Discard commits, advised for private branch

git reset <commit-ish>

Reword the previous commit message

git commit -v --amend

See commit history for just the current branch

git cherry -v master

Amend author.

git commit --amend --author='Author Name <[email protected]>'

Reset author, after author has been changed in the global config.

git commit --amend --reset-author --no-edit

Changing a remote's URL

git remote set-url origin <URL>

Get list of all remote references

git remote

Alternatives:

git remote show

Get list of all local and remote branches

git branch -a

Get only remote branches

git branch -r

Stage parts of a changed file, instead of the entire file

git add -p

Get git bash completion

curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc

What changed since two weeks?

git log --no-merges --raw --since='2 weeks ago'

Alternatives:

git whatchanged --since='2 weeks ago'

See all commits made since forking from master

git log --no-merges --stat --reverse master..

Pick commits across branches using cherry-pick

git checkout <branch-name> && git cherry-pick <commit-ish>

Find out branches containing commit-hash

git branch -a --contains <commit-ish>

Alternatives:

git branch --contains <commit-ish>

Git Aliases

git config --global alias.<handle> <command> 
git config --global alias.st status

Saving current state of tracked files without commiting

git stash

Alternatives:

git stash push

Saving current state of unstaged changes to tracked files

git stash -k

Alternatives:


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap