欢迎使用Git工具进行项目管理
git status:
which displays a list of the files that have been modified since the last time changes were saved.
git add: 把文件加入暂存区
git add -A
: stages Allgit add .
: stages new and modified, without deletedgit add -u
: stages modified and deleted, without new
所以git add -A
等于git add .; git add -u
git add filename
: To add a file to the staging area
git diff:
without any filenames will show you all the changes in your repository
git diff filename
: to compare the file as it currently is to what you last saved
git diff directory
: will show you the changes to the files in some directory.
git diff -r HEAD path/to/file
: To compare a file’s current state to the changes in the staging area. The-r
flag means “compare to a particular revision”,HEAD
is a shortcut meaning “the most recent commit”
git diff -r HEAD~1
: The labelHEAD~1
then refers to the commit before it, whileHEAD~2
refers to the commit before that, and so on.
git commit:
To save t he changes in the staging area.
git commit -m "write your log message here."
: to save the changes in the staging area with your log message.
If you use a command git commit
without message ,you will open a log editors.
【Tip】:To save what you have written, type Ctrl+O to write the file out, then Enter to confirm the filename, then Ctrl+X and Enter to exit the editor.
git commit -a
:–all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
git log:
to view the log of the project’s history.
When you run git log
, Git automatically uses a pager to show one screen of output at a time. Press the space bar to go down a page or the q key to quit.
git log path"
: to inspect only the changes to particular files or directories.wherepath
is the path to a specific file or directory. The log for a file shows changes made to that file; the log for a directory shows when files were added or deleted in that directory, rather than when the contents of the directory’s files were changed.
git show:
To view the details of a specific commit.
git show 77d3
: you can use the commandgit show
with the first few characters of the commit’s hash.
git branch: 获取当前项目所使用分支
git checkout: 新建分支
git checkout -b Hailin/leetcode:
: 新建一个在“Hailin”目录下的“leetcode”分支,并切换到其上
git命令行下面显示中文字符:
由于Git默认引用非ASCII 字符,disable它的引用行为可以用下面的命令:
git config --global core.quotepath false
git config –global user.name “Your Name”
git config –global user.email you@example.com
git stash: 保存当前工作进度,会把暂存区和工作区的改动保存起来
git stash save 'message...'
: 可以添加一些注释
git stash list
: 显示保存进度的列表。也就意味着,git stash命令可以多次执行。
git stash pop
:恢复最新的进度到工作区。git默认会把工作区和暂存区的改动都恢复到工作区。
git stash pop --index
: 恢复最新的进度到工作区和暂存区。(尝试将原来暂存区的改动还恢复到暂存区)
git stash pop stash@{1}
: 恢复指定的进度到工作区。stash_id是通过git stash list命令得到的
通过git stash pop命令恢复进度后,会删除当前进度。
git stash drop [stash_id]
: 删除一个存储的进度。如果不指定stash_id,则默认删除最新的存储进度
git stash clear
: 删除所有存储的进度。
git stash apply [–index] [stash_id]
: 除了不删除恢复的进度之外,其余和git stash pop 命令一样。