赞
踩
一、安装Git
MAC 上安装Git主要有两种方式
首先查看电脑是否安装Git,终端输入:
git
安装过则会输出:
WMBdeMacBook-Pro:~ WENBO$ git usage: git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>] These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status grow, mark and tweak your common history branch List, create, or delete branches checkout Switch branches or restore working tree files commit Record changes to the repository diff Show changes between commits, commit and working tree, etc merge Join two or more development histories together rebase Reapply commits on top of another base tip tag Create, list, delete or verify a tag object signed with GPG collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects 'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help <command>' or 'git help <concept>' to read about a specific subcommand or concept.
1、通过homebrew安装Git
1、未安装homebrew,需安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、安装git
brew install git
2、通过Xcode安装
直接从AppStore安装Xcode,Xcode集成了Git,不过默认没有安装,你需要运行Xcode,选择菜单“Xcode”->“Preferences”,在弹出窗口中找到“Downloads”,选择“Command Line Tools”,点“Install”就可以完成安装了。
二、创建ssh key、配置git:
三、使用http方法:
https://blog.csdn.net/qq_41055045/article/details/99941324
输入密码时要输出token,参考:https://blog.csdn.net/weixin_41010198/article/details/119698015
拉取分支
在clone处复制https的链接。
$ git clone https://github.com/zlu1994/yolov5_pytorch.git
Cloning into 'yolov5_pytorch'...
Username for 'https://github.com': zlu1994
Password for 'https://zlu1994@github.com':
四、修改当前分支
git branch -a (查看所有分支)
git checkout dev1 (切换到dev1分支)
git status (查看当前分支状态)
git add . (修改完之后添加)
git commit -m “add:…” (添加提交记录)
git status (提示用“git push”提交即可)
git push 或者 git push origin develop
git stash 先暂存
git pull 拉取最新的
git git stash pop 暂存的那个pop出来
git stash list 暂存的列出来
git reset --hard 08496f80eebe1ae12ef06f73830be9a3e1e5… 下载历史版本中的某一个
五、复制分支
参考:https://www.jianshu.com/p/75c50836fbfa
如果我们需要在现有分支的基础上,复制代码到新分支进行开发,并推送至远程仓库,可以进行如下操作:
注:old-branch为旧分支名,new-branch为新分支名
使用git bash打开命令行界面,使用以下命令检出远程分支。
$ git checkout -b old-branch origin/old-branch
从当前分支复制出新的分支
$ git checkout -b new-branch
把新建的分支push到远程库
$ git push origin new-branch:new-branch
拉取远程分支
$ git pull # 经过验证,当前的分支并没有和本地分支关联,根据提示进行下一步
关联
$ git branch --set-upstream-to=origin/new-branch new-branch
再次拉取,成功
$ git pull
下面就可以在新复制的分支上进行修改了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。