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

[经验分享] Elf Sundae's Blog

[复制链接]

尚未签到

发表于 2018-1-15 06:35:11 | 显示全部楼层 |阅读模式
  References:
  http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide
  http://www.kernel.org/pub/software/scm/git/docs/
  http://progit.org/book/
  git安装、配置用户名邮箱、SSH服务器搭建
  http://www.cnblogs.com/elfsundae/archive/2011/07/06/2099182.html
  Create/List/Remove a new Project/Repository
  $ git init
  将在当前目录创建一个隐藏的名为".git"的目录。
  $ git init project1
  等价于 $ mkdir project1 && cd project1 && git init
  $ git status
  检查当前目录是否包含一个git repo
  $ ls .git
  查看git目录
  $ rm -rf .git/
  移除有关git的所有东西
  Configure git to ignore files
  .gitignore文件可以定义要忽略的文件。详细规则见http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
  过滤文件夹: /build/
  过滤某种类型的文件:  *.tmp
  过滤某各文件: /Build/Products/test.app
  !开头表示不过滤: !*.c , !/dir/subdir/
  支持通配符: *.[oa] 过滤repo中所有以.o或者.a为扩展名的文件
  有三种方法应用过滤:


  • 对该repo的所有用户应用过滤:  将 .gitignore 文件放在工作目录的跟目录,编辑.gitignore完成后提交
      git add .gitignore

  • 仅对自己的repo备份过滤:  添加/编辑你工作目录的$GIT_DIR/info/exclude,例如你的working copy目录是
      ~/src/project1 , 则路径为
      ~/src/project1/.git/info/exclude

  • 系统全局过滤  创建一个ignore文件,名字随意起,比如我的放在 ~/.gitglobalignore ,然后配置git:
      $ core.excludesfile = ~/.gitglobalignore

  .gitignore文件示例:
  

.DS_Store### build directoryiMochaApp/build/  iMochaSDK
/build/### Testing projects directory/Testing/  

  Getting the latest Code
  

$ git pull <remote> <branch> # fetches the code and merges it into                             # your working directory$ git fetch <remote> <branch> # fetches the code but does not merge                              # it into your working directory  $ git pull
--tag <remote> <branch> # same as above but fetch tags as well$ git fetch --tag <remote> <branch> # you get the>  

  Checking Out Code (clone)
  $ git clone user@host.com/dir/to/repo [Target DirName]
  Commit Changes
  当修改了文件,你需要提交(commit)这些更改。
  $ git commit source/main.c
  上句将提交 ./source/ 目录下的 main.c 文件。
  $ git commit -a
  -a标识表示提交所有修改过的文件,但是不提交新增加的文件。新增加的文件需要使用$ git-add 将其添加到git的索引中。
  “提交”仅改变你本地repo,如果要提交更改到服务器,需要使用push:
  $ git push <remote> <branch>
  查看当前状态
  $ git status 可以查看当前工作与那个branch,将要提交什么,提醒你忘记了什么等等...
  Undo/Revert/Reset a commit
  如果不想让当前的更改生效,返回之前的提交,可以运行如下命令:
  # Revert to a previous commit by hash:
  $ git-reset --hard <hash>
  可使用 HEAD^ 快捷指定上一次提交hash:
  # Revert to previous commit:
  $ git-reset --hard HEAD^
  文件比较
  比较命令是 $ git diff
  # to compare 2 revisions of a file:
  $ git diff <commit1> <commit2> <file_name>
  # to compare current staged file against the repository:
  $ git diff --staged <file_name>
  #to compare current unstaged file against the repository:
  $ git diff <file_name>
  How do you see the history of revisions to a file?
  $ git log -- filename
  git branch (分支)
  git默认分支叫 master
  # create a new branch
  $ git branch <branch-name>
  # to see a list of all branches in the cureent repoitory
  $ git branch
  # if you want to switch to another branch you can use
  $ git checkout <branch-name>
  # to create a new branch and switch to it in one step
  $ git checkout -b <branch-name>
  # to delete a branch:
  $ git branch -d <branch-name>
  # to create a branch with the changes from the current branch,do :
  $ git stash
  $ git stash branch <branch-name>
  How do you merge branches?
  if you want to merge a branch(e.g. "master" to "release"), make sure your current branch is the target branch you'd like to merge into(use $git branch or $git status to see your current branch).
  Then use
  $ git merge master
  (where master is the name of the branch you want to merge with the current branch).
  If there are any conflicts, you can use
  $ git diff
  to see pending conflicts you have to resolve.
  跟踪远程分支
  假设你已经clone了一个具有 'some_branch' 分支的远端repo.下面的命令将本地跟踪这个分支:
  

# list remote branchesgit branch -r# start tracking one remote branchgit branch --track some_branch origin/some_branch# change to the branch locallygit checkout some_branch# make changes and commit them locally....# push your changes to the remote repository:git push  

  创建远程分支
  

# create a new branch locallygit branch name_of_branch  git checkout name_of_branch
# edit/add/remove files  #
...  #
Commit your changes locallygit add fileName  git commit
-m Message# push changes and new branch to remote repository:git push origin name_of_branch:name_of_branch  

  删除远程分支
  git push [远程名] :[分支名]
  $ git push origin :mybranchname

运维网声明 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-435203-1-1.html 上篇帖子: 256code, 生活与技术 下篇帖子: 如何在 Visual Studio 中使用 Git 同步代码到 CodePlex
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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