Giter Site home page Giter Site logo

blog's People

Contributors

jun58 avatar

blog's Issues

Git 相关

(鉴于git的操作看10遍忘11遍的节奏,这里记录一些git相关的操作,不断更新)

git 问题(tips)集合

  • git log 乱码问题

    set LC_ALL=C.UTF-8
    
  • git diff 只显示尚未暂存成功的改动,而并不是自上次提交以来所有的改动。

  • git commit 会启动文本编辑器以便输入本次提交的说明(默认会启用shell的环境变量**$EDITOR**所指定的软件,一般都是vim或emacs)

  • 想把文件从Git仓库中删除,但仍希望保存在当前目录中(亦即从缓存区移除)。

    换句话说,你想让文件保存在磁盘,但是并不想让Git继续跟踪。

    (e.g. 当你忘记添加.gitignore 文件,一不小心把一个很大的日志文件或一堆.a这样的编译生成的文件添加到暂存区的时候。)

    使用--cached 选项:

    $ git rm --cached README

远程仓库的使用

查看远程仓库

1.git remote 列出远程服务器的简写(默认是origin)

$ cd my-app
$ git remote
origin

2.git remote -v列出远程服务器的简写与其对应的URL

$ git remote -v
origin https://github.com/demo/my-app (fetch)
origin	https://github.com/demo/my-app (push)
添加远程仓库

1.如果你的项目是克隆来的git clone ,你克隆的仓库就是这个项目的远程仓库

git remote -v
// 远程仓库默认origin,后面链接就是你 git clone 的链接
origin https://github.com/demo/my-app (fetch)
origin	https://github.com/demo/my-app (push)

2.如果你在github 或者是别的地方建了仓库repository想和本地的项目关联。使用git remote add <name> <url>

cd my-app
git init
git remote add origin https://github.com/demo/my-app
git remote -v
origin https://github.com/demo/my-app (fetch)
origin	https://github.com/demo/my-app (push)
从远程仓库中抓取与拉取

git fetch [remote-name]

这个命令会访问远程仓库,从中拉取你还没有的数据。执行完成后,你将会拥有那个远程仓库中所有分支的引用,可以随时合并或查看。

如果你克隆clone了一个仓库,命令会自动将其添加为远程仓库并默认以 "origin" 为简写,所以,git fetch origin 会抓取克隆(或者上一次抓取)后新推送的所有工作。

注意: git fecth 命令会将数据拉取到你的本地分支,它并不会自动合并或修改你当前的工作。当你准备好的时候必须手动合并到你的工作。

git pull

如果你有一个分支设置为跟踪一个远程分支,可以使用git pull 命令来自动的抓取然后合并远程分支到当前分支。git pull = git fetch && git merge

分支

远程分支

​ 删除 git push origin --delete <name>

查看提交历史

git log 
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <[email protected]>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number
    

git log命令不用任何参数默认会按时间顺序列出所有的更新,列出每个提交的SHA-1校验和,作者的名字和邮箱,提交时间及提交说明。

参数介绍
  • -p 显示每次提交的内容差异,(也可以加上-2来仅显示最近的两次提交),相当于提交之前的 git diff

    git log -p -2
  • --stat 显示每次提交的就简略的统计信息

    git log --stat
    commit ca82a6dff817ec66f44342007202690a93763949
    Author: Scott Chacon <[email protected]>
    Date:   Mon Mar 17 21:52:11 2008 -0700
    
        changed the version number
    
     Rakefile | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
  • --pretty 指定使用不同于默认格式的方式展示提交的历史,这个参数往往和一些内建的子选项一起使用(单独的--prettygit log 效果一样):

    1.oneline 将每个提交放在一行展示

    git log --pretty=oneline
    ca82a6dff817ec66f44342007202690a93763949 changed the version number
    085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test
    a11bef06a3f659402fe7563abf99ad00de2209e6 first commit

    2.format 定制显示记录的格式, 常用的选项 列出了常用的格式占位符写法及其代表的意义

    $ git log --pretty=format:"%h - %an, %ar : %s"
    ca82a6d - Scott Chacon, 6 years ago : changed the version number
    085bb3b - Scott Chacon, 6 years ago : removed unnecessary test
    a11bef0 - Scott Chacon, 6 years ago : first commit

参考资料

https://git-scm.com/book/zh/v2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.