设为首页 收藏本站
查看: 762|回复: 0

[经验分享] Git 学习收集贴

[复制链接]

尚未签到

发表于 2018-9-19 07:29:21 | 显示全部楼层 |阅读模式
http://jonas.iki.fi/git_guides/ The Git Guides  http://wiki.laptop.org/go/Git_Tips  git技巧集
  http://marc.info/?l=git  有很多git相关的问答
  http://www.kernel.org/pub/software/scm/git/docs/user-manual.html  用户手册
  http://git.or.cz/gitwiki/GitTips  Git小技巧
  http://utsl.gen.nz/talks/git-svn/intro.html#feature-branches  git-svn好资料
  http://bazaar-vcs.org/BzrVsGit  Bzr与Git的比较
  http://www.dont-panic.cc/capi/?s=git
  为什么说 Git 将取代 SVN 做软件版本控制? http://www.javaeye.com/news/4503-tortoisegit-windows-user-to-use-git tortoisegit: Windows用户使用Git的福音
  http://rubynroll.javaeye.com/blog/203133
  SVN+GIT=鱼与熊掌兼得http://docs.google.com/View?id=dfwthj68_675gz3bw8kj Git 魔法 [文章推荐]Comparison of revision control softwarehttp://en.wikipedia.org/wiki/Comparison_of_revision_control_software$ git commit --amend  http://cworth.org/hgbook-git/tour/ 中有介绍,
  好像是可修改前一次提交的msg
  $ git stash save "some message" 当遇到一个小BUG但又不想马上解决,要等到你过段时间才解决的时候
  $ git stash list
  $ git stash apply [--index] []  (恢复状态)
  $ git stash clear (clear all)
  $ git stash drop [stash ]  (clean one)
  $ git stash pop  [stash ]  (clean one and apply)
  [am = apply mail]
  $ git am -3 patches.mbox
  $ git fetch origin todo:my-todo-work
  $ git fetch git://example.com/proj.git master:example-master
  从origin仓库中将提取出来的master分支放到新创建的example-master分支中,相当于新建一个分支代替master
  $ git count-objectsRecovering from repository corruption$ git-fsck --full
  $ git log SHA1 --> SHA1 只要hexdig的前6-8个就行了
  7.错误提交了commit怎么办?
  a) git-revert
  这个本身就会产生一个commit,如果用得多了会让你的log看起来不那么干净。;-)
  b) git-reset
  用这个要当心,它会把那个commit之后的commit全部删除。一个好的办法是:先建立一个临时的分支,然后再git-reset,再git-rebase,最后再删除临时的分支。 详细可以看这里。
$ git commit --amend 修订上一次提交的msg  $ git commit -s --amend
  < >-s, --signoff         add Signed-off-by: header
  --amend               amend previous commitHow to change commits deeper in historygit rebase --onto   .
  git filter-branch can also be usefull. It has been ported from the obsoleted Cogito's .How to get only merges in gitk?gitk --full-history -- a//b
  What to do if you have realized that you are on wrong branch?git checkout -m      -m                    merge local modifications into the new branchRecovering lost changes
  $ git log master@{1}
  $ git show master@{2}                             # See where the branch pointed 2,
  $ git show master@{3}                             # 3, ... changes ago.
  $ gitk master@{yesterday}                         # See where it pointed yesterday,
  $ gitk master@{&quot;1 week ago&quot;}                      # ... or last week
  $ git log --walk-reflogs master # show reflog entries for master
  $ git show HEAD@{&quot;1 week ago&quot;} #=======================================================================
  在工作目录下修改 .gitignore 来ingore一些文件  如 src/*.bak    tmp/*
  git config --global color.diff auto
  git config --global color.status auto
  git config --global color.branch auto
  git config --global branch.autosetupmerge auto
  git config --global user.name &quot;Your Name Comes Here&quot;
  git config --global user.email you@yourdomain.example.com
  git apply      patch -p0 相当于打补丁  git-format-patch 生成补丁
  git pull       svn update
  git-revert(1) to undo botched commits.  与svn的revert不同,如想达到svn效果用 reset
  $ git-checkout -f foo.c 这招强制覆盖
  $ git fetch /home/bob/myrepo master:bob-incoming
  这个命令将 Bob 的 master 分支的导入到名为 bob-incoming 的分支中( 不同于 git-pull 命令,git-fetch 命令只是取得 Bob 的开发工作的拷贝, 而不是合并经来)。接着:
$ git whatchanged -p master..bob-incoming  $ git repack 打包  $ git prune-packed 清除已打包后多余的东东 对比查看.git/object目录下的内容 find .git/objects -type f
  $ git branch -D branch-name (delete branch)
  $ git whatchanged
  $ git checkout -b new v2.6.13  从v2.6.13版出中创建一个new分支开始work
  $ git branch -r  其中-r 是remote的意思,如果带有 -d xx表示删除远程的branch
  $ git checkout -b my-todo-copy origin/todo
  Note that the name &quot;origin&quot; is just the name that git uses by default to refer to the repository that you cloned from.
$ git add -X &quot;*.bak&quot;  .  $ git show HEAD^:path/to/file
  $ git am --resolved
  $ git clone --bare ~/proj proj.git   制作共享仓库
  $ touch proj.git/git-daemon-export-okExporting a git repository via http$ mv proj.git /home/you/public_html/proj.git
  $ cd proj.git
  $ git --bare update-server-info
  $ chmod a+x hooks/post-update
  $ git push ssh://yourserver.com/~you/proj.git master:master
  $ cat >>.git/config  reset --hard HEAD@{1}
   man git-rev-parse会有树状的图表示  isa-^n 表示回退n  isa~n 中的n表示n个 ^1 , ^HEAD 表示排除
  git-fetch -v 相当于update远程数据到本地来,相当于svn update  --> git-pull 才更新数据到本地,才发现对比有数据变更,还要再学学
   git-log --color                      git-branch --color
  git-branch $USER/work 可以生成像目录树一样的branch ,也可以同样方法生成tag, git-tag $USER/mytag , 在生成 brahcn or tag可以  branch mybranch master^2 ==>表示基于master^2来生成分支,同理可用于tag
   git fetch origin --> origin表示远程clone的仓库,  git-merge origin/master 表示将远程的master分支内容merge到本地当前分支, 另一招 git-branch foobar origin/foobar $git-checkout foobar就相当于origin/foobar,方便
  git-push origin myLocalBranch:RemoteExistBranch 提交, 如果已创建了tags的话可以$git-push --tags origin
   $git-push origin  :refs/heads/ 在本地仓库向远程创建一个新分支, :refs这种语法采用 .git/refs目录这种结构
  git-push origin  :  清除远程分支,注意,前面的: 前没有是空的 , $git-push origin :refs/tags/清tag
  清理                    $git-remote prune                      $git-branch -d (delete) -r (remote)  清掉远程的RemoteBranch分支
  git-checkout -b work 自动创建一个work分支并checkout过去
  $git-whatchanged -p                        $git-checkout HEAD~7 foobar.c                    $git-show HEAD~7:foobar.c >foobar~7.c
  git-format-patch 生成补丁,默认用的是-2  ,可以设置为-3
  $git-stash 很有用,
   $git-repack                    $git-prune                     $git-gc  --prune --aggressive 清查仓库
  git checkout -m
  git rebase --onto   
   比较两个本地仓库GIT_ALTERNATE_OBJECT_DIRECTORIES=../repo/.git/objects git-diff-tree $(GIT_DIR=../repo/.git git rev-parse --verify HEAD) HEAD
  方法2:GIT_ALTERNATE_OBJECT_DIRECTORIES=../repo/.git/objects cg-diff -r `GIT_DIR=../repo/.git cg-object-id -c HEAD`..HEAD
  How to remove all files which are missing from working directory?$git ls-files -z --deleted | git update-index -z --remove --stdin$ git ls-files -o --exclude-standard >> .gitignore
  
  $ cat >>.git/config

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-593858-1-1.html 上篇帖子: Using Git with SVN 下篇帖子: Everyday GIT With 20 Commands Or So[zt]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表