Git Learning reference: HTTPS://GIT-SCM.COM/BOOK/ZH/V2
Common commands
git init
Initialize Project
git add *.java
Add files to git version control (all files for. java suffix)
There are three states of Git, commited (committed), modified (modified), staged (staged), and submitted representations of data that have been safely saved in the local database. Modified to indicate that the file was modified but not yet saved to the database. Staged indicates that the current version of a modified file has been marked for inclusion in the next commit snapshot.
This introduces the concept of three working areas of a git project: Git repositories, working directories, and staging areas.
git status -s
The current state, generally have the next step of the prompt information -s
output concise information
git commint -m ‘提交描述信息‘
Submit to local Warehouse
git clone https://github.com/xuelingxiao/java-knowledge-structure knstuct
Cloning a remote repository and renaming
> GitHub 有一个十分详细的针对数十种项目及语言的 .gitignore 文件列表,你可以在 https://github.com/github/gitignore 找到它.
git diff
See which changes have not yet been staged, and see which changes are staged for the next commit;
git diff --cache
View Staging Area
git commit -a
Skipping add, staging the trace files and committing them together
git rm filename.txt
To remove a file from tracking status
git rm --cached filename
Remove files from staging area, keep workspace files
git mv filefrom fileto
Moving files
git log
View commit History
git log -p -2
-P shows the difference in content per commit, 2 shows the last two commits, commonly used git log --graph
,, git log --pretty=oneline[short,full,fuller,format]
and git log -Sfunctionname
git log --grep 关键字
others see Help
git commit --amend
Amend will be used to fix the last commit, such as the last commit if you forget some files, you can use this command to repair, GIT will amend file with the previous file as a single commit
git reset HEAD 文件名.txt
Cancel Staging
git checkout -- 文件名
It is dangerous to undo changes to the file, because local modifications may be overwritten by files from the far end
git remote -v
View remote Repository information for configuration,-V shows the shorthand and URL saved by git
git remote add knstuct https://github.com/https://github.com/xuelingxiao/java-knowledge-structure
Add Remote Warehouse Configuration
git fetch knstuct
Get the repository, that is, the mirror is synchronized to the local
git pull knstuct
Pull the remote branch to local and merge, Fetch does not merge
git push -f remote-name branch-name
Push to remote,-F rolls back version (Force push)
git remote show origin
View more information on a remote branch
git remote rename oldname newname
Remote Branch Rename
git remote rm branch-name
To remove a remote branch
git tag
List labels
git tag -l ‘v1.8.5*‘
List only labels for the v1.8.5 series
git tag -a v1.1 -m ‘v1.1版本的标签‘
Create a note tag (git tags are divided into two categories: lightweight and sticky notes, note tags that store a complete object in a git database, and can be checked to include tagged people)
git tag v1.2 -lw
Play Light weight Labels
git push origin v1.1
Push tags to the remote so you can share tags
git checkout -b brahchname tagname
Check out the label, actually check out the label version to the workspace-B just for the first time checkout use
- Alias settings, see example below
$ git config --global alias.co checkout$ git config --global alias.br branch$ git config --global alias.ci commit$ git config --global alias.st status$ git config --global alias.unstage ‘reset HEAD --‘--上面命令运行后,下面两条语句等价$ git unstage fileA$ git reset HEAD -- fileA--如果是外部命令, 可以在命令前加!$ git config --global alias.visual ‘!gitk‘
git merge branch master
Merging branches
git rebase master
You have to use less if you can't control it.
Git-flow
How the planning team uses Git, a set of specifications that uses git; You can refer to Google's gitflow.
git hooks
Can be used in CI, automatically released, integrated with Jenkins.
Through this study, we can basically deal with the needs of the ordinary. As part of engineering, Git learns so much (and then, if you have time later, to sort out more about Git), the next step is to learn Jenkins.
Four Java Engineering--git Foundation