Git命令使用

欢迎使用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 All
  • git add . : stages new and modified, without deleted
  • git 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-rflag means “compare to a particular revision”, HEAD is a shortcut meaning “the most recent commit”
git diff -r HEAD~1: The label HEAD~1 then refers to the commit before it, while HEAD~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.where path 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 command git 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 命令一样。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值