git init
一开始初始化repogit clone (remote repository only)
一开始从某地址克隆repo.git
Git自动生成的文件夹,用来保存history.gitignore
一个文件用来忽略某一类文件或文件夹,比如一类文件*.mp4或者[Db]ebug文件夹git add .
添加所有文件到stage状态git add filename
添加某文件到stage状态,叫stagedgit status
查看当前的状态git restore --staged filename
取消某文件的stage状态,叫unstagegit commit -m "Message"
将staged的文件保存,并附上message,可以理解为保存为一个版本git stash
临时保存当前所有的文件的修改状态到抽屉,将修改恢复到最新保存(有记录/Commit过的)的版本。可以理解为临时保存当前游戏记录,并且恢复到上一个记录点。git stash -m "Message
类似于commit的用法,在stash基础上加messagegit stash list
查看抽屉的列表git stash apply
恢复到最新的临时保存的状态,可以将最新的stash记录取出来。可以理解为恢复最新的临时记录。git stash pop stash@{0}
恢复某临时记录code .
在CLI上输入后,可以调用VS Code- VS Code里文件有U的标识,意思是Untracked
git push
用作将local repo更新到remotegit fetch
从remote往本地拉取最新信息,同步信息git pull
将remote拉取到本地sync
就是pull push结合- Remote repository 和 Local repository是彼此独立,两者是同步的关系。local不能直接commit到remote。通常是用commit提交到到local,再把本地的repository的版本提交到remote。
- origin/xx 是一个remote的标识
git rm filename
意思是将某文件从git中移除,rm后,查看状态git status
会发现在rm的文件会在staged状态,需要commit后,文件和记录才会真正被移除。(某文件不想再被version control了)git restore --staged delected-filename
这个可以将rm的文件变回unstaged状态,再使用checkout恢复出来,前提是rm后没有commit。git checkout .
获取某branch的最新历史版本,rm后立刻用的话可以可以立马恢复到最新的历史版本。git clean -f
假如需要将所有新创建的文件清除,可以用clean。这个操作会删除文件的,所有要加-f意思是force强制的意思。这个不影响modified的文件,只针对新增的文件。git revert hashvalue
commit一个新版本,恢复到某版本,message和恢复的版本一样。git revert --abort
终止revertgit reset hashvalue --soft
soft reset到之前某版本,修改了的差异是放在staged状态。这个还会保存之前的记录,只不过隐藏起来了。git reset hashvalue --hard
hard reset到之前某版本,之前的记录会被真正的删除。git diff
对比两个版本的不一样git branch
查看branch有哪些,目前在哪branchgit branch <branch name>
创建新的branchgit checkout master
切换到master,或者某branchgit checkout -b <branch name>
创建新的branch并且切换到新的banch- branch命名规则,
<type>/<ticket-number>-<title>
, 一般用在feature、fix/bugfix/hotfix,chore. git merge feat1
在当前的branch,选择将feat1合并到当前branch,feat1历史记录也会进来git merge <branch name> --abort
git merge <branch name> --overwrite-ignore
git merge <branch name> --no-overwrite-ignore
git log --all --decorate --oneline --graph
图形化显示所有banch和loggit rebase <branch name>
rebase合并记录,并且在一条线上git push <name> <local_branch>:<remote_branch>
- 正常工作情况,每天工作都要pull一下最新的remote master
- git remote add origin https://github.com/xx/xx.git
- git push -u origin master
- A branch is a divergence from the main repository and essentially an independent line of code development.
The general process of reviewing a pull request
- Read the pull request description
- Comment on lines of code that need feedback
- Submit review
- Take a look again, repeat if needed
The steps (in order) to successfully create and merge a pull request
- Submit pull request with description
- Make changes from feedback
- Merge code
The major steps in the Github flow
- Work on a specific branch
- Commit changes and push code to remote repository
- Create pull request
- Discuss pull request with reviewers
- Merge branch once pull request accepted
About Pull Request
- Having smaller pull requests is preferred because it leads to the pull requests being reviewed faster and more thoroughly. how-to-write-a-good-pull-request Walkthrough of Two Codecademy Pull Requests
Examples
- A short pull request to remove trailing spaces on the Codecademy docs repository which is immediately approved.
- A long pull request to add a new component on the Codecademy gamut repository which includes screenshots, comments, and a lively discussion before being approved.
CLI 一些用法
echo > filename
可以创建文件,并且输入多行文字,回车保存, 会覆盖记录echo "message" > filename
将一行文字保存到某文件,会覆盖记录echo >> filename
可以创建文件,并且输入多行文字,回车保存, 不会覆盖,而是继续添加在文本后echo "message" >> filename
将一行文字保存到某文件,不会覆盖,而是继续添加