Git 学习笔记

来源:互联网 发布:金钥匙注音软件 编辑:程序博客网 时间:2024/05/29 10:43

Git学习笔记

    • Git学习笔记
      • 前言
      • Git笔记
        • 和远程仓库连接
        • 上传项目
        • 克隆github 项目
        • 删除操作
        • 下载文件
        • 系统总结
        • 参考链接

前言

git 是一个非常炫酷的代码管理工具,提到git,就不得不提到程序员必备的github. 它有着下面的几个优点

  • 免费使用
  • 上面有着各种开源项目,可以用来实践
  • 可以方便的管理你的代码,特别是当你和别人合作一个项目时
  • 也可以用来管理博客和写小说

Git笔记

使用它首先你得有一个github的账号,其次你得在你的电脑上安装好git。

  • 和远程仓库链接
  • 上传项目
  • 克隆github项目
  • 删除操作
  • 下载文件
  • 系统总结
  • 参考链接

1. 和远程仓库连接

先在github账号下设置好你得秘钥,通过秘钥和远程端连接,个人觉得最直接的好处就是Git每次提交时不用输密码
clone 操作时选择clone ssh型地址,可以省去你来回输入账号密码的时间
ssh -T git@github.com

2. 上传项目

新建文件夹右键用gitbash 打开git命令窗口。
输入git init初始化

和远程库链接
git remote add origin
git@github.com:mathlf2015/learn_python.git
若出现错误fatal: remote origin already exists
git remote rm origin
继续和远程库链接
将变化加入缓存
git add--all
显示加载缓存的变化
git status -s
为改动标注(引号内内容)
git commit -m 'test'
可能需要(从网上更新本地库)
git pull origin master
相当于是从远程获取最新版本并merge到本地

推送本地文件
git push origin master
输入(账号,密码)
(账号,密码)

3. 克隆github 项目

首先在网站上进入别人的库
先把你所需项目‘fork’,如人气极高的jquery框架,你可以访问它的项目主页https://github.com/jquery/jquery,点“Fork”(右上角)就在自己的账号下克隆了一个jquery仓库,然后,从自己的账号下clone

clone仓库一定要从自己的账号下克隆,这样你才能推送修改。如果从jquery的作者的仓库地址克隆,因为没有权限,你将不能推送修改。
新建文件夹
右键进入git bash
git init

和远程库链接()内为你所需库的地址或者你自己账号fork的地址
git remote add origin git@github.com:zhuyujia/css.git)
下载到本地文件夹
git clone (git@github.com:zhuyujia/css.git)

4. 删除操作

4.1 gitup项目中文件夹
进入gitup项目文件夹下点击进入文件,文件中间右方有删除键

4.2 githup中项目
进入 gitup 项目 找到setting按钮,点击,鼠标拖至右下方,找到‘delete this repository’

5.下载文件

  1. 找到要下载的文件
  2. 点击在GitHub上打开
  3. 找到右上角的“Raw”按钮
  4. 右击“另存为…”,也可以Option/Alt + Click

6. 系统总结

git init creates a new Git repository
git status inspects the contents of the working directory and staging area
git add adds files from the working directory to the staging area
git diff shows the difference between the working directory and the staging area
git commit permanently stores file changes from the staging area in the repository
git log shows a list of all previous commits

返回历史操作
git checkout HEAD filename: Discards changes in the working directory.
git reset HEAD filename: Unstages file changes in the staging area.
git reset SHA: Can be used to reset to a previous commit in your commit history.

增加多个文件
git add filename_1 filename_2

合并分支
git branch: Lists all a Git project’s branches.
git branch branch_name: Creates a new branch.
git checkout branch_name: Used to switch from one branch to another.
git merge branch_name: Used to join file changes from one branch to another.
git branch -d branch_name: Deletes the branch specified.

合作更新项目
The workflow for Git collaborations typically follows this order:

Fetch and merge changes from the remote
Create a branch to work on a new project feature
Develop the feature on your branch and commit your work
Fetch and merge from the remote again (in case new commits were made while you were working)
Push your branch up to the remote for review

git clone: Creates a local copy of a remote.
git remote -v: Lists a Git project’s remotes.
git fetch: Fetches work from the remote into the local copy.
git merge origin/master: Merges origin/master into your local branch.
git push origin : Pushes a local branch to the origin remote.

7. 参考链接

参考链接1
参考链接2
福利给大家介绍个好用的在线编程学习网站

0 0
原创粉丝点击