美文网首页
git本地仓库搭建(windows,github)

git本地仓库搭建(windows,github)

作者: Pppppy | 来源:发表于2017-08-07 18:30 被阅读0次

What

*中文翻译感觉比较拗口,直接搬了英文解释

Git: a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files.

一分钟介绍Git-youtube video

  • Git GUI: aimed at people who don't like the coding on black screens, it provides a graphical user interface to run the git commands.

  • Git bash: bash is a Unix shell and command language, and is the default shell on Linux and OS X. In laymen terms, the git which runs on the terminal of any Linux device is known as git bash.

  • Git CMD(command line prompt) is the command-line interpreter on Windows operating systems. Sort of an equivalent to the terminal in Linux.

  • GitHub: a web-based Git or version control repository and internet hosting service. It offers all the distributed version control and source code management (SCM) functionality of Git as well as adding its own features.

*总结一下,就是一个通过Git进行版本控制的软件源代码托管服务。号称全球最大男性交友平台(误)

Why

  • 在本地和远程各有一个git仓库用来储存自己的代码,两个仓库可以进行同步
  • GitHub上的仓库可以作为备份,还可以通过该仓库和他人协作

How

  1. 在github中创建一个新的仓库(repository)
image.png
  1. 在本地创建一个文件夹,利用终端Git CMD进入文件夹目录, 执行初始化命令。
    git init
    这一步的目的在于把这个文件夹变成Git可以管理的仓库。
image.png

这一步成功后, Git自动在文件夹里创建一个.git的目录,用于跟踪管理版本库。

image.png
  1. 将本地仓库和远程仓库进行关联
git remote add origin git@github.com:username/repository path.git
image.png
  1. 关联成功以后,还不能推送同步到远程仓库。本地Git和GitHub仓库之间传输是通过SSH加密的,但现在所用的SSH key是public key,不在自己的GitHub账户列表里。所以需要配置SSH key验证信息。
  • 首先使用Git Bash生成SSH Key
$ ssh-keygen -t rsa -C "yourgithubemail@example.com"
  • 使用默认路径,命令会在C:\Users\Administrator中生成.ssh文件夹。使用记事本打开其中的id_rsa.pub,复制内容(ssh key)。
image.png
  • 进入github,Account-》Settings-》SSH and GPG keys,新建SSH key,将复制的key粘贴进去。
image.png
  • 添加完成后,可以使用如下命令检查是否成功。
$ ssh -T git@github.com
Hi tianqixin! You've successfully authenticated, but GitHub does not provide shell access.

Git的简要流程

以下摘自Git教程: http://www.runoob.com/git/git-tutorial.html

  • Workflow
    workflow
    你可以提出更改(把它们添加到暂存区Index)
$ git add [file name]

你可以提交改动到head, 但这一步改动还没有到你的远端仓库
Records file snapshots permanently in version history

$ git commit -m"[descriptive message]”

你可以推送你的改动,从而把改动提交到远端仓库。master可以换成你想要推送的任何分支

$ git push origin master

假如你操作失误,你可以替换掉本地改动

$ git checkout --[filename]

此命令会使用 HEAD 中的最新内容替换掉你的工作目录中的文件。已添加到暂存区的改动以及新文件都不会受到影响。

  • Branch 分支
branch

创建一个名字叫做feature_x的分支,并切换过去

$ git checkout -b feature_x

切换回主分支

$ git checkout master

删掉新建的分支

$ git branch -d feature_x

将分支推送到远程仓库,才能被他人所看到

$ git push origin[branch]

-更新与合并
要更新你的本地仓库至最新改动

$ git pull

在你的工作目录中获取(fetch)并合并(merge)远端的改动

  • 要合并其他分支到你当前的分支(例如master)
$ git merge [branch]
  • 可能会出现冲突,这时候就需要手动修改这些文件来手动合并这些冲突。改完之后,可以将它们标记为合并成功。
$ git add [file name]
  • 在合并改动前,你可以使用如下命令预览差异
$ git diff [source_branch][target_branch]
  • 标签
    创建一个叫做1.0.0的标签
$ git tag 1.0.0 1b2e1d63ff

后面那一串字符是你想要标记的提交ID的前10位字符(也可以使用少几位,只要能确定唯一性),可以使用以下命令获取

$ git log

常用Git命令

Git完整命令手册

  • Configure Tooling 配置工具
  1. set the name you want attached to your commit transaction.
$ git config --global user.name"[name]"
  1. set the email you want attached to your commit transaction
$ git config --global user.email"[email address]"
  1. enable helpful colorization of command line output
$ git config --global color.ui auto
  1. 内置图形化git
$ gitk
  1. 历史记录每个提交信息只显示一行
$ git config format.pretty oneline
  1. 交互式添加文件到暂存区
$ git add -i
  • Creating repositories 创建仓库
  1. 创建一个新的本地仓库
$ git init [project-name]
  1. 创建一个本地仓库的克隆版本
$ git clone /path/to/repository
  1. 创建一个远程服务器仓库的克隆版本
$ git clone username@host:/path/to/repository
  • Making changes 更改替换
  1. Lists all new or modified files to be committed
$ git status
  1. Shows file differences not yet staged
$git diff
  1. Shows file differences between staging and the last file version
$ git diff --staged 

-Group changes 群更改

1. Lists all local branches in the current repository

$ git branch

2. Creates a new branch

$ git branch [branch-name]

3. Switches to the specified branch and updates the working directory

$ git checkout [branch-name]

4. Combines the specified branch’s history into the current branch

$ git merge [branch]

5. Deletes the specified branch

$ git branch -d [branch-name]


-**Refactor filenames**: relocate and remove files

  1. Deletes the file from the working directory and stages the deletion
$ git rm [file] 
  1. Removes the file from version control but preserves the file locally
$ git rm --cached [file] 
  1. Changes the file name and prepares it for commit
$ git mv [file-original] [file-renamed] 

-Superess tracking: exclude temporary files and paths

  1. A text file named .gitignore suppresses accidental versioning of files and paths matching the specified patterns
*.log build/ temp-*

  1. Lists all ignored files in this project
$ git ls-files --other --ignored --exclude-standard 

-Save fragments: Shelve and restore incomplete changes

  1. Temporarily stores all modified tracked files
$ git stash 
  1. Lists all stashed changesets
$ git stash list 
  1. Restores the most recently stashed files
$ git stash pop 
  1. Discards the most recently stashed changeset
$ git stash drop 

-Review history: Browse and inspect the evolution of project files

  1. Lists version history for the current branch
$ git log 
  1. Lists version history for a file, including renames
$ git log --follow [file] 
  1. Shows content differences between two branches
$ git diff [first-branch]...[second-branch] 
  1. Outputs metadata and content changes of the specified commit
$ git show [commit] 

-Redo commits: Erase mistakes and craft replacement history

  1. Undoes all commits after [commit], preserving changes locally
$ git reset [commit] 
  1. Discards all history and changes back to the specified commit
$ git reset --hard [commit] 

-Synchronize changes: Register a repository bookmark and exchange version history

  1. Downloads all history from the repository bookmark
$ git fetch [bookmark] 
  1. Combines bookmark’s branch into current local branch
$ git merge [bookmark]/[branch] 
  1. Uploads all local branch commits to GitHub
$ git push [alias] [branch] 
  1. Downloads bookmark history and incorporate changes
$ git pull

相关文章

  • git本地仓库搭建(windows,github)

    What *中文翻译感觉比较拗口,直接搬了英文解释 Git: a version control system (...

  • 将本地git仓库关联至远程git仓库 2019-11-20(未经

    如何将本地git仓库关联至远程git仓库 以本地git仓库关联GitHub仓库为例: 在github上新建仓库(注...

  • 发布自己的cocoapods插件

    创建本地Git仓库,并提交代码 创建GitHub远端仓库,提交本地代码至GitHub仓库GitHub创建仓库.pn...

  • 建立远程仓库

    建立远程仓库,无非就是想把本地创建的git仓库上传到github仓库,达到本地和github的同步,首先进入git...

  • github 常用指令

    github 常用指令git clone 用于下载github仓库中代码到本地。例如仓库:git://gi...

  • 2019-01-22 git本地仓库关联远程仓库

    如果先有本地git仓库,怎么关联远程仓库(github)呢? 先在GitHub新建一个仓库,仓库名可以和本地的仓库...

  • 2018-07-02-6

    Git在 windows 使用方法 在继续阅读后续内容前,请自行注册GitHub账号。由于你的本地Git仓库和Gi...

  • git总结

    本地文件夹关联远程仓库 在github上新建远程仓库, 在本地文件夹下 git init 添加远程仓库:git ...

  • git学习(下)

    将自己本地的git仓库和远程的git仓库关联上 git remote add origin git@github....

  • Git 最简单使用帮助

    初始化并同步仓库 先在GitHub创建好仓库 在本地,打开Git命令行,输入git init初始化本地仓库 git...

网友评论

      本文标题:git本地仓库搭建(windows,github)

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