赞
踩
查看git版本
PS D:\SourceTree\repository\practiceServer> git --version
git version 2.35.1.windows.2
查看命令说明,回车展示更多命令,q退出
使用 git help <command>,查看指定命令的使用,会打开本地html页面
PS D:\SourceTree\repository\practiceServer> git help -a
See 'git help <command>' to read about a specific subcommand
Main Porcelain Commands
add Add file contents to the index
am Apply a series of patches from a mailbox
archive Create an archive of files from a named tree
bisect Use binary search to find the commit that introduced a bug
branch List, create, or delete branches
...
git help checkout
从远端仓库克隆分支到本地
git clone https://xxxx/xx/
拉取远程仓库的更新到本地,默认拉取的分支是绑定的远端分支(使用命令git branch -vv 查看关联情况)
可以使用 git pull origin master 指定远程仓库的分支
PS D:\SourceTree\repository\practiceServer> git pull
Already up to date.
PS D:\SourceTree\repository\practiceServer> git pull origin master
推送本地的更新到远程仓库,默认拉取的分支是绑定的远端分支(使用命令git branch -vv 查看关联情况)
可以使用 git push origin master 指定远程仓库的分支
PS D:\SourceTree\repository\practiceServer> git push
Everything up-to-date
PS D:\SourceTree\repository\practiceServer> git push origin master
Everything up-to-date
查看本地分支与远程分支关联情况。
PS D:\SourceTree\repository\practiceServer> git branch -vv
* master 80126bc [origin/master]
将本地分支推送命令关联到远程分支
PS D:\SourceTree\repository\practiceServer> git push --set-upstream origin master
Everything up-to-date
branch 'master' set up to track 'origin/master'.
将本地分支拉取命令关联到远程分支
PS D:\SourceTree\repository\practiceServer> git pull --set-upstream origin master
* branch master -> FETCH_HEAD
Already up to date.
查看当前分支状态
PS D:\SourceTree\repository\practiceServer> git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
...
切换分支,提交点等
git checkout master
git checkout 提交点
git add .
添加所有修改的文件;
git add 文件名
添加单个文件;
git add file1 file2 file3
添加多个文件。
PS D:\SourceTree\repository\practiceServer> git add .
PS D:\SourceTree\repository\practiceServer> git add filename
fatal: pathspec 'filename' did not match any files
(这是找不到文件,乱写的文件名)
git commit提交代码,git commit -m “注释”,加注释提交代码
说明:提交代码只是提交到本地仓库,要更新到远程仓库需要用git push。
PS D:\SourceTree\repository\practiceServer> git commit -m "修改"
On branch master
nothing to commit, working tree clean
暂存区内的文件,想要保留修改仅取消暂存():
可以使用git restore --staged 文件名;
多个文件 git restore --staged 文件名1 文件名2
所有文件git restore --staged .
说明:该命令是新的文件也适用;没有–staged就是另外一个命令。
PS D:\SourceTree\repository\practiceServer> git restore --staged filename
对未进入暂存区的文件撤销修改,不影响已经进去暂存区的修改。
// 撤销所有未进入暂存区的修改
PS D:\SourceTree\repository\practiceServer> git restore .
// 撤销指定文件未进入暂存区的修改
PS D:\SourceTree\repository\practiceServer> git restore filename
error: pathspec 'filename' did not match any file(s) known to git // filename就是指定的文件名,报错是因为没有文件
未跟踪的新文件:Untracked files
git clean -f . 是移除全部
git clean -f 文件名是移除单个文件
参数:
-i 显示要做什么,并以交互方式清理文件
可以使用git help clean查看命令的使用说明
PS D:\SourceTree\repository\practiceServer> git clean -f .
Removing xxx/test/Test.java
PS D:\SourceTree\repository\practiceServer> git clean -f xxx/test/Test.java
Removing xxx/test/Test.java
查看git远程仓库地址
PS D:\SourceTree\repository\practiceServer> git remote -v
origin https://xxx/java/practiceServer.git (fetch)
origin https://xxx/java/practiceServer.git (push)
rm就是remove移除的缩写,remote是远程的,origin是源端
PS D:\SourceTree\repository\practiceServer> git remote rm origin
由于ip改变什么的需要重新关联本地仓库到远程仓库地址,使用git remote add origin
PS D:\SourceTree\repository\practiceServer> git remote add origin https://xxx/java/practiceServer.git
当我们想要切换到别的分支或者历史提交点,但又不想破坏当前工作区的改动,可以使用git stash命令将当前的改动存放起来,stash是隐藏、存放。类似于存放在栈中。
git stash list查看存放的工作区;git stash pop弹出存放的工作区。
原文解释:
Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.
PS D:\SourceTree\repository\practiceServer> git stash
Saved working directory and index state WIP on master: 871e604 修改
查看远程所有分支,-r是remote远端
git branch -r
查看用户名,邮箱
git config user.name
git config user.email
设置用户名,邮箱
git config user.name "用户名"
git config user.email "邮箱"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。