Mac 版 IDEA 中配置 GitLab

打印 上一主题 下一主题

主题 539|帖子 539|积分 1617

一、安装Git

在mac终端输入Git检测指令,可以通过git命令检察Git是否安装过,假如没有则会弹出安装按钮,假如安装过则会输出如下信息。
  1. WMBdeMacBook-Pro:~ WENBO$ git
  2. usage: git [--version] [--help] [-C <path>] [-c name=value]
  3.            [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
  4.            [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
  5.            [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
  6.            <command> [<args>]
  7. These are common Git commands used in various situations:
  8. start a working area (see also: git help tutorial)
  9.    clone      Clone a repository into a new directory
  10.    init       Create an empty Git repository or reinitialize an existing one
  11. work on the current change (see also: git help everyday)
  12.    add        Add file contents to the index
  13.    mv         Move or rename a file, a directory, or a symlink
  14.    reset      Reset current HEAD to the specified state
  15.    rm         Remove files from the working tree and from the index
  16. examine the history and state (see also: git help revisions)
  17.    bisect     Use binary search to find the commit that introduced a bug
  18.    grep       Print lines matching a pattern
  19.    log        Show commit logs
  20.    show       Show various types of objects
  21.    status     Show the working tree status
  22. grow, mark and tweak your common history
  23.    branch     List, create, or delete branches
  24.    checkout   Switch branches or restore working tree files
  25.    commit     Record changes to the repository
  26.    diff       Show changes between commits, commit and working tree, etc
  27.    merge      Join two or more development histories together
  28.    rebase     Reapply commits on top of another base tip
  29.    tag        Create, list, delete or verify a tag object signed with GPG
  30. collaborate (see also: git help workflows)
  31.    fetch      Download objects and refs from another repository
  32.    pull       Fetch from and integrate with another repository or a local branch
  33.    push       Update remote refs along with associated objects
  34. 'git help -a' and 'git help -g' list available subcommands and some
  35. concept guides. See 'git help <command>' or 'git help <concept>'
  36. to read about a specific subcommand or concept.
复制代码
安装Git的方式有三种:
【方式一】通过homebrew安装Git: Homebrew是macOS的一个包管理工具,假如未安装homebrew,需先安装homebrew
  1. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
复制代码
再通过如下命令安装git
  1. brew install git
复制代码
【方式二】Git官网下载最新git Mac版本安装: 下载地址 Binary installer二进制安装,点击下载的git-2.27.0-intel-universal-mavericks.dmg安装。
【方式三】安装Xcode: Xcode安装完太大,占用空间,假如不必要安装Xcode,最好选择方式二安装git。打开终端输入git会弹出安装Xcode和安装git或者打开App Store搜刮Xcode安装。Xcode是Apple官方IDE,功能非常强盛,是开发Mac和IOS App的必选装备,而且是免费的。它集成了Git和一些插件,但是安装起来很大
二、配置Git 【创建ssh key】

【1】设置username和email: 通过终端输入以下命令来配置用户名和邮箱,这些信息将用于记载你全部的提交汗青:也可以通过git config --list检察已经设置的配置信息。
  1. git config --global user.name "username"
  2. git config --global user.email "email"
复制代码
【2】创建SSH Key: 在利用Git进行远程仓库的推送Push或拉取Pull时,为了验证你的身份通常必要利用SSH密钥。在终端中输入ssh-keygen,然后按下回车,接着连续按三次回车即可在你的用户目次(一样平常是/Users/your_name)下生成.ssh文件夹,并包罗你的SSH Key。
  1. ssh-keygen -t rsa -C "useremail"
  2. Last login: Sat Jan  6 14:12:16 on ttys000
  3. WMBdeMacBook-Pro:~ WENBO$ ssh-keygen -t rsa -C "useremail"
  4. Generating public/private rsa key pair.
  5. Enter file in which to save the key (/Users/username/.ssh/id_rsa):
  6. /Users/username/.ssh/id_rsa already exists.
  7. Overwrite (y/n)? y
复制代码
方式一: 在终端检察.ssh/id_rsa.pub文件:
  1. open .ssh/id_rsa.pub
复制代码
回车后,就会新弹出一个终端,然后复制里面的key。
方式二: 用cat命令检察
  1. cat .ssh/id_rsa.pub
复制代码
【3】将SSH Key添加到你的GitHub 或者GitLab账号或其他远程仓库的账户设置中,就可以开始你的代码托管之旅。

点击New SSH key:

添加key:

【4】通过ssh -t 进行验证,输出如下信息表示成功。
  1. ssh -T git@github.com
  2. Last login: Sat Jan  6 18:32:35 on ttys000
  3. WMBdeMacBook-Pro:~ WENBO$ ssh -T git@github.com
  4. Hi wenmobo! You've successfully authenticated, but GitHub does not provide shell access.
  5. WMBdeMacBook-Pro:~ WENBO$
复制代码
三、配置IDEA

在终端通过where git找到git位置,再进入setting页面选择或者搜刮Git并配置Path to Git executable即可。

四、Git基本操作

安装和配置完Git之后,你可以创建本身的代码仓库并进行基本的操作,如:
【1】利用git init初始化一个新的Git仓库。
【2】利用git add <file>或git add .来添加文件到暂存区。
【3】利用git commit -m "your message"将暂存区的改动提交到仓库。
【4】利用git push将本地仓库的更改推送到远程仓库。
【5】利用git clone <repository>克隆一个远程仓库到本地。
【6】利用git pull将远程仓库的更改拉取到本地。
总结: Git在现代软件开发中饰演着不可或缺的脚色,而macOS提供了友好和简洁的情况来支持开发者利用Git。在mac上安装、配置Git并执行基本操作是每个开发者的基础技能。无论你是一个刚入行的新手,照旧一个有经验的老手,希望本文能够帮助你在mac情况下更加得心应手地利用Git。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

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

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

不到断气不罢休

金牌会员
这个人很懒什么都没写!

标签云

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