赞
踩
目录
参考链接:
- 查看版本号:git -v
- 配置用户:git config --global user.name 'huanhaunwang'
- 配置邮箱:git config --global user.email 'whh@nit.zju.edu.cn'
- 保存配置:git config --global credential.helper store
- 查看配置:git config --global list
- git clone http://github.xxx.com
- mkdir learn-git
- cd learn-git
- git init / git init my-repo # 初始化my-repo仓库
- cd .git
- ls -alltr
- 工作区——>暂存区:git add .
- 暂存区——>本地仓库:git commit -m 'xxx' # 'xxx'为commit的描述
- ###### 添加和提交文件
- 初始化本地仓库:git init
- 查看状态:git status
- 工作区-->暂存区:git add .
- --> 提交txt文件到暂存区:git add *.txt
- --> 删除暂存区内容:git rm --cached <file>
- 暂存区-->本地仓库:git commit -m 'description'
- 写内容到file1.txt:echo 'This is the first file' > file1.txt
- 提交记录:git log/ git log --oneline
git reset三种模式 | 工作区 | 暂存区 |
git reset --soft | ||
git reset --hard | ❌ | ❌ |
git reset --mixed | ❌ |
(工作区/暂存区/本地仓库,不同版本v1/v2/v3,不同分支)
- git diff v1_num v2_num
- git diff HEAD~ HEAD
- git diff HEAD~2 HEAD
- git diff HEAD~3 HEAD
- git diff HEAD~3 HEAD <file>
- git diff HEAD^ HEAD
- git diff <branch_name> <branch_name>
- 工作区&暂存区同时删除:git rm <file> --> git commit -m 'delete <file>'
- 工作区删除-->暂存区删除-->本地仓库删除:rm <file> --> git add <file> / git add. --> git commit -m 'delete <file>'
- 暂存区缓存删除:git rm --cached <file>
- 忽略所有log日志:echo '*.log' > .gitignore --> git add . --> git commit -m 'commit .gitignore'
- 忽略temp下的所有内容:echo 'temp/' > .gitignore --> git add . --> git commit -m 'commit .gitignore'
- 忽略所有的.a文件:*.a
- 忽略任何目录名为temp/的文件夹
- 查看分支:git branch
- 创建分支:git branch/checkout <branch-name>
- 切换分支:git switch <branch-name>
- 合并分支:切换到main/master主分支 --> git merge <branch-name>
- 删除分支:
- (1)已合并:git branch -d <branch-name>
- (2)未合并:git branch -D <branch-name>
- 查看分支创建&合并流程:git log --graph --oneline --decorate --all
- 解决合并:vi <main_conflict.txt> --> git add . --> git commit -m 'solve conflict'
- 终止合并:git merge --abort
- 克隆远程仓库:git clone ssh链接(此命令需要提前配好ssh -key.pub)
- 给远程仓库命别名:git remote add <远程仓库别名> ssh链接
- e.g. git remote add origin git@github.com:xxx/xxx/xxx.git
-
- 切换分支:git branch main/master
- 推送本地 --> remote远程:git push -u <远程仓库别名> <分支名>
- 查看远程仓库:git remote -v
- 拉取remote远程 --> 本地:git pull / git pull -u <远程仓库别名> <远程分支名>:<本地分支名>
-
- (1)远程-->本地:
- 1)手动修改远程
- 2)拉取到本地:git pull = git fetch + git merge
- (2)本地-->远程:
- 1)手动修改本地文件
- 2)添加至缓存区:git add.
- 3)提交到本地仓库:git commit -m 'description'
- 4)推送/更新远程仓库:git push
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。