Git相关

作者: 蜗牛1992 | 来源:发表于2016-09-03 22:14 被阅读8次

简单的Git

1,cd 到项目目录
2,git init
3,git add .
4,将git创建分支时的
echo "# Location" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/YQL539/Location.git
git push -u origin master  

复制到shell里面,点击enter即可提交到github,中间需要输入git账户名字:YQL539  密码:密码

显示进度,成功。

下面是以前写的,留着做参考:
一,找到git仓库:finder打开项目,找到隐藏文件.git

终端:Mac显示隐藏文件:defaults write com.apple.finder AppleShowAllFiles YES,强制退出finder,重新打开finder.

如果项目没有隐藏的Git文件夹:

1,打开终端,cd 工程目录,

2,指令:git Init

3,git add .//点,第一次提交的时候需要三四步。

4,git commit -m "Initial commit"

在打开就有git文件夹了

二,提交代码,Xcode source control 里面,commit,

提交之前回滚之前代码discard all,或者discard 单个文件

三,提交之后回滚之前版本:

终端,cd 工程目录.

git reflog //查看提交日志,前面是版本号

git reset --hard 版本号//即可回到之前版本,hard强制执行,可多次执行,回到不同的版本

扩展:git config alias.rst 'reset --hard'//增加别名:用rst 取代reset --hard,换git文件夹的时候即换项目时候,失效。

四,上传到gitHub:

1:创建SSH Key

ozil:tmp mesut$ cd ~
ozil:~ mesut$ pwd
/Users/mesut
ozil:~ mesut$ cd .ssh
-bash: cd: .ssh: No such file or directory
ozil:~ mesut$
进入当前的用户目录,波浪线表示的是当前目录。判断是否已经安装了.ssh,避免默认安装会覆盖之前安装的。明显当前目录没有该文件

执行创建 ssh key

ssh-keygen -t rsa -C youremail@example.com(你的Github登陆名)
接着都是回车,选择默认的目录,默认的密码即可

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mesut/.ssh/id_rsa):
Created directory '/Users/mesut/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mesut/.ssh/id_rsa.
Your public key has been saved in /Users/mesut/.ssh/id_rsa.pub.
接着可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对

ozil:~ mesut$ cd .ssh
ozil:.ssh mesut$ ls
id_rsa id_rsa.pub
2:在Github设置ssh key

登陆Github, “Settings”->SSH keys->Add SSH key

title:可以顺便填名字

key:在Key文本框里粘贴id_rsa.pub文件的内容

点击add key 配置完成

3:测试本地是否和Github连接上

ozil:.ssh mesut$ ssh -T git@github.com
The authenticity of host 'github.com (xxx)' can't be established.
RSA key fingerprint is xxx.
Are you sure you want to continue connecting (yes/no)? yes
第一次链接Github,会有一个确认,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes回车即可。
Warning: Permanently added 'github.com,xxx' (RSA) to the list of known hosts.Hi tanchongshi! You've successfully authenticated, but GitHub does not provide shell access.

4.使用git在本地建立的项目更新到Github

首先在本地初始化一个git仓库

由于之前没有配置用户名,所以首次commit会有提示,自动建立

设置方式

$ git config --global user.name Your Name
$ git config --global user.email email@example.com
为了把本地库推到远程服务器,首先需要在Github上面也建一个项目

在Repository name填上我们的项目名字,description随便填,别的默认。

然后会生成项目

然后把远程项目和本地库关联:cd 到.git 目录

ozil:hellogithub mesut$ git remote add origin git@github.com:tanchongshi/hellogithub.git
ozil:hellogithub mesut$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'XXX' to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 217 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:tanchongshi/hellogithub.git

  • [new branch] master -> master
    Branch master set up to track remote branch master from origin.
    完成
    配置之后,提交新项目到github 只要cd 进入目录,1,git init 2,git add .3,将github里面新建项目中复制
    echo "# Location" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin https://github.com/YQL539/Location.git
    git push -u origin master

复制到shell里面,点击enter即可提交到github

相关文章

  • git基本命令

    git常用命令 git丢弃更改相关 git连接远程仓库相关 git切换分支相关 git stash相关 git标签相关

  • 前端 | Git的学习

    文章目录 Git相关命令 Git相关命令 git init :初始化本地git目录,生成 .git 文件夹 git...

  • 2019-06-26: Git 相关?

    一:Git相关 '--------------------------git pull--------------...

  • Git相关

    关联到GitHub http://www.runoob.com/git/git-remote-repo.html

  • Git相关

    更新 fork 的仓库 https://github.com/lxconan/java/blob/master/s...

  • git相关

    常见命令 git help git config --global user.name "一纸砚白" git co...

  • git 相关

    2018年3月27日15:31:29 用eclipse 用习惯了,换着思维使用一下git,服务器用的是coding...

  • git相关

    https://www.jianshu.com/p/52694939213b

  • git相关

    本地创建新分支: git checkout -b 新分支名字 或者 git branch 新分支名字 git br...

  • git 相关

    1,git clone .. 克隆远程分支到本地。 2,git checkout branchName 在本地切换...

网友评论

      本文标题:Git相关

      本文链接:https://www.haomeiwen.com/subject/gfclettx.html