技术控

    今日:47| 主题:49507
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Lesser known Git commands

[复制链接]
美麗的邂逅∮ 发表于 2016-9-30 22:34:30
314 9

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Git has a strong commitment to backwards compatibility: many powerful features are hidden behind options rather than exposed as default behaviour. Fortunately Git also supports aliases , so you can create your own commands that do all manner of Git magic. Here’s a selection of the more useful (or at least entertaining) aliases defined in my  .gitconfig :
  git please

  [code]$ git config --global alias.please 'push --force-with-lease'[/code]   Every developer has had the chat with their team lead about force pushing to a shared branch (i.e. don’t do it). Rebasing, amending, and squashing. are all good fun right up until you rewrite some shared history and spill duplicate commits all over your repository. Fortunately, Git won’t let you rewrite history on the server willy-nilly. You have to explicitly pass the --force option to git push to show you mean business. But force pushing is a bit heavy handed: it stomps the upstream branch with your local version, and any changes that you hadn’t already fetched are erased from history.
         
Lesser known Git commands-1 (lesser,known,git,commands,git,shell,commands,git,known,hosts,lesser)
          Quality meme courtesy of    @tarkasteve        Git’s  --force-with-lease   option is far more polite: it checks that your local copy of the ref that you’re overwriting is up-to-date before overwriting it. This indicates that you’ve at least fetched the changes you’re about to stomp. Since git push --force-with-lease is rather a lot to type out each time, I’ve created a polite alias for it: git please
  git commend

  [code]$ git config --global alias.commend 'commit --amend --no-edit'[/code]   Ever commit and then immediately realize you’d forgotten to stage a file? Fret no more! git commend quietly tacks any staged files onto the last commit you created, re-using your existing commit message. So as long as you haven’t pushed yet, no-one will be the wiser.
  [code]$ git add Dockerfile$ git commit -m ‘Update Bitbucket pipeline with new Docker image’# (facepalm)$ git add bitbucket-pipelines.yml$ git commend[/code]  git it

  [code]$ git config --global alias.it \'!git init && git commit -m “root” --allow-empty'[/code]   The first commit of a repository can not be rebased like regular commits, so it’s good practice to create an empty commit as your repository root. git it both initializes your repository and creates an empty root commit in one quick step. Next time you spin up a project, don’t just add it to version control: git it !
  [code]$ cd shiny-new-thing$ git itInitialized empty Git repository in /shiny-new-thing/.git/[master (root-commit) efc9119] root[/code]  git staaash

  [code]$ git config --global alias.stsh 'stash --keep-index'$ git config --global alias.staash 'stash --include-untracked'$ git config --global alias.staaash 'stash --all'[/code]    git stash   is one of the most delightful and useful Git commands. It takes any changes to tracked files in your work tree and stashes them away for later use, leaving you with a clean work tree to start hacking on something else. However if you’ve created any new files and haven’t yet staged them, git stash won’t touch them by default, leaving you with a dirty work tree. Similarly, the contents of untracked or ignored files are not stashed by default.
   I’ve created a few handy aliases to handle different variations of git stash , based on which bits of your work tree you need to stash:
  [code]git stsh      # stash only unstaged changes to tracked filesgit stash     # stash any changes to tracked filesgit staash    # stash untracked and tracked filesgit staaash   # stash ignored, untracked, and tracked files[/code]   If in doubt, the long one ( git staaash ) will always restore your worktree to what looks like a fresh clone of your repository.
  git shorty

  [code]$ git config --global alias.shorty 'status --short --branch'[/code]   I run  git status  probably more than any other Git command. Git’s inline help has gotten a lot more friendly over the years, which is excellent for beginners, but the output is overly verbose for those more familiar with Git. For example, git status emits 18 lines to tell me that I have a couple of staged, unstaged, and untracked changes:
  [code]$ git statusOn branch masterChanges to be committed:  (use “git reset HEAD …” to unstage)[/code]  [code]modified: package.json[/code]  [code]$ git config --global alias.commend 'commit --amend --no-edit'0[/code]  [code]modified: package.json[/code]  [code]$ git config --global alias.commend 'commit --amend --no-edit'2[/code]  [code]$ git config --global alias.commend 'commit --amend --no-edit'3[/code]   git shorty tells me the same thing in 3 lines:
  [code]$ git config --global alias.commend 'commit --amend --no-edit'4[/code]   (OK, so I actually have this aliased as git st for brevity, but I couldn’t resist.)
  git merc

  [code]$ git config --global alias.commend 'commit --amend --no-edit'5[/code]   If you’re using a standard non-rebasing branching workflow, running a standard git merge to combine feature branches with master is actually not ideal. With no options, git merge uses the --ff merge strategy, which will only create a merge commit if there are no new changes on the master branch, otherwise it simply “fast forwards” your master branch to point at the latest commit on your feature branch. Only sometimes creating a merge commit makes it tricky to reason about which code was developed on which branches when looking through your git history.

Lesser known Git commands-2 (lesser,known,git,commands,git,shell,commands,git,known,hosts,lesser)
        git merc uses the --no-ff strategy, to always create a merge commit.
1234下一页
友荐云推荐




上一篇:Docker存储空间扩容(DeviceMapper Driver)
下一篇:A simple workflow for deep learning
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

asdafafaf 发表于 2016-10-1 07:02:56
美麗的邂逅∮很有经验啊!
回复 支持 反对

使用道具 举报

柒年 发表于 2016-10-1 17:00:04
我也来顶一下..
回复 支持 反对

使用道具 举报

夏恋蜜语丶 发表于 2016-10-1 17:40:12
帮顶,帮顶,快速顶贴中・・・・・・
回复 支持 反对

使用道具 举报

rtooj 发表于 2016-10-2 00:18:27
我消极对待减肥,能不能取消我胖子的资格啊
回复 支持 反对

使用道具 举报

kfaqk 发表于 2016-10-4 03:19:10
在乎的人不明白,明白的人不在乎。
回复 支持 反对

使用道具 举报

李志高 发表于 2016-10-10 11:30:17
楼主你想太多了!
回复 支持 反对

使用道具 举报

熙雯 发表于 2016-10-14 12:36:33
各位兄台,通融通融,沙发我来啦!
回复 支持 反对

使用道具 举报

Bean 发表于 2016-11-8 09:54:56
打酱油的人拉,回复下赚取积分
回复 支持 反对

使用道具 举报

刘甜甜 发表于 2016-11-11 10:00:59
如果恐龙是人,那刘甜甜是什么?  
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表