Giter VIP home page Giter VIP logo

cli's Introduction

command-line interface

  • curl代码,重定向到指定文件名
curl -L https://raw.githubusercontent.com/FrankFang/nodejs-test/master/index.js > index.js
  • 修改bash的命令
vim ~/.bashrc  //打开文件
内容:
alias    gst='git status -sb'   //修改命令
  • 更改npm配置文件(progress)
npm config set key value
npm config set progress:true  //显示进度信息

参考:
https://docs.npmjs.com/cli/config
https://docs.npmjs.com/misc/config

  • 拷贝文件(file0 --> file1)
cp -r file0 file1
  • git 跳转至指定版本
git log
git reflog
> 44d4d0e HEAD@{0}: commit: 3
> fe6cd0f HEAD@{1}: commit: 2
> 997b12c HEAD@{2}: commit: 1

git reset --hard hash
  • 公钥查询
cat ~/.ssh/id_rsa.pub
  • 合并分支
git xx xxx
  • window下打开文件目录
start .   //打开当前目录
  • 打印文件内容
cat a.html b.html   //输出两个文件内容
  • 移动、重命名文件
mv a.html ..  //移动a.html至上级目录
mv a.html b.html  //a.html重命名为b.html
  • 复制文件到目录
cp a.html ..  //复制a.html到上级目录
git reset --hard HEAD^
  • 设置淘宝镜像
注:打开DOS面板,执行npm config set registry https://registry.npm.taobao.org

如果想恢复默认,打开DOS面板,执行npm config set registry https://registry.npmjs.org
  • 复制ssh的公钥(window)
$ pbcopy < ~/.ssh/id_rsa.pub
  • 取消该文件再工作区的修改
$ git checkout -- file
  • 查看合并分支图
git log --graph
运行 npm config set loglevel http,让你知道 npm 发的每一个请求
运行 npm config set progress false,关闭那个进度条
为了让你的安装速度变快,运行 npm config set registry https://registry.npm.taobao.org/
如果上面的配置让你在运行 npm adduser 的时候出了问题,只需要 npm config delete registry 即可想要恢复成原样。没出问题就别运行 npm config delete registry。
  • 添加鼠标右键 以管理员权限打开终端,输入下面命令(先把cmder添加到系统变量中)
Cmder.exe /REGISTER ALL

cli's People

Contributors

yongheng2016 avatar

Watchers

James Cloos avatar

cli's Issues

linux & ; && 区别

1. command1 & command2 & command3

三个命令同时执行

2. command1; command2; command3

不管前面命令执行成功没有,后面的命令继续执行

3. command1 && command2

只有前面命令执行成功,后面命令才继续执行

pm2

官方

  • 启动应用
pm2 start xx启动命令xx  --name=xx域名xx
  • 删除应用
pm2 delete xx域名xx
  • 列出所有命令
pm2 list

git push 无法推送错误

事件还原:

一: 我在github上新建了一个仓库xxx,并条件生成了.gitignore,README.md文件

二: 在本地一个文件,需要提交到xxx远程仓库,但我2b的进行了如下操作

git init
git add .
git commit -m 'add'
git remote add origin @git.xxxxx.xxx
git push -u origin master
  • 后开始报错,如下:

image

经过查找stackove,找到方法:

方法1:(多人协作禁止使用)

git push -u origin master -f   //强制推送,禁止检查,可能会导致远程仓库之前更新的内容丢失

参考:https://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge

方法2:

  • 每次操作前记得git pull
git pull origin master  //先合并远程和本地
  • 此时又报了一个错误
fatal: refusing to merge unrelated histories  //因为我的本地仓库文件README.md和远程的不一致,导致冲突

参考:https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories

  • 可以用这个命令解决,但最好还是确认下两边用哪一个
git pull origin branchname --allow-unrelated-histories

接下来就可以push了



  • 在我的github上新建了一个名为temp的仓库,里面只有一个README.md文件

  • 而此时我本地有一个目录,里面只有一个文件a.html

  • 当我在本地shell中进行了如下操作后:
git init 
git add .
git commit -m 'add'
gi 
  • 会出现以下报错:报错信息大概就是你的本地仓库和远程仓库内容不一致,提交被拒绝了

  • 但如果我用--force或简写-f强行提交也能提交上,但分发生了可怕的结果,本地仓库完全覆盖了远程仓库的内容,远程仓库独有的文件 丢失

  • 强行提交后你会发现,temp仓库中只有推送过来的a.html文件,而原本的README.md文件没了,所以强行提交不太可取,如果是团队协作中你-f了,准备跑路吧

当你在force之前

git fetch  //git pull down latest change form your machine
git log origin/master //对比远程分支的log

Git版本回退

  • 场景1:仅改动了工作区某文件,但未提交到暂存区,想丢弃工作区的修改
git reset checkout file
  • 场景2:改动了工作区某个文件,并且提交到了暂存区,分两步回退
git reset HEAD file     //回到场景1,再操作场景1下的步骤回退
  • 场景3:提交了不合适的版本时,想撤销本次提交(前提时没有提交的远程仓库)
git reset --hard HEAD^ //回退上个提交,^的个数代码表向前回退多少个版本
git reset --hard xxxxxxx //回退到某个版本号下

覆盖某个状态的commit

  1. 移动指针
git reset xxx   // 回退到生成commit的前一个状态
  1. 覆盖提交信息
git commit --amend

Git分支管理

  • 通常直接合并分支时,Git会用Fast forward模式,此模式下,删除分支后会丢掉分支信息
  • 强制禁止Fast forward模式,merge时会生成新的commit
git merge --no-ff -m "merge with no-ff" dev
  • 在开其它分支之前,不想提交现有分支内容,可以先暂存
git stash  //暂存储
恢复
git stash apply   //但是恢复后,stash内容并不删除,你需要用git stash drop来删除;
git stash pop   //恢复的同时把stash内容也删了
git stash apply stash@{0}   //恢复指定暂存

  • 多个stash下如何全部恢复?

git alias

將一些git的命令alias起來,方便以後加快速率,以下是我alias起來的。

git config --global alias.ci commit
git config --global alias.st status
git config --global alias.last 'log -1 HEAD' 查看上一次的提交訊息
git config --global alias.unstage 'reset HEAD --'

以下這些資訊都存在~/.gitconfig裡,所以其實也可以直接去這邊進行修改。

另外,git也可以加入版本號碼,這方面的資訊可以搜尋 git tag。

https://noootown.wordpress.com/2015/06/19/git-first-use/

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.