cli's Issues
linux & ; && 区别
1. command1 & command2 & command3
三个命令同时执行
2. command1; command2; command3
不管前面命令执行成功没有,后面的命令继续执行
3. command1 && command2
只有前面命令执行成功,后面命令才继续执行
pm2
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。
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下如何全部恢复?
覆盖某个状态的commit
- 移动指针
git reset xxx // 回退到生成commit的前一个状态
- 覆盖提交信息
git commit --amend
Git版本回退
- 场景1:仅改动了工作区某文件,但未提交到暂存区,想丢弃工作区的修改
git reset checkout file
- 场景2:改动了工作区某个文件,并且提交到了暂存区,分两步回退
git reset HEAD file //回到场景1,再操作场景1下的步骤回退
- 场景3:提交了不合适的版本时,想撤销本次提交(前提时没有提交的远程仓库)
git reset --hard HEAD^ //回退上个提交,^的个数代码表向前回退多少个版本
git reset --hard xxxxxxx //回退到某个版本号下
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
- 后开始报错,如下:
经过查找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的正确姿势
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.