jun58 / blog Goto Github PK
View Code? Open in Web Editor NEWjun58 blog
Home Page: https://github.com/jun58/blog
jun58 blog
Home Page: https://github.com/jun58/blog
(鉴于git的操作看10遍忘11遍的节奏,这里记录一些git相关的操作,不断更新)
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
指定使用不同于默认格式的方式展示提交的历史,这个参数往往和一些内建的子选项一起使用(单独的--pretty
和git 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.