当前位置:首页 > 编程笔记 > 正文
已解决

git命令清单

来自网友在路上 165865提问 提问时间:2023-11-02 03:05:20阅读次数: 65

最佳答案 问答题库658位专家为你答疑解惑

一、设置和配置

1.初始化一个新的仓库:
git init
2.克隆(Clone)一个远程仓库到本地:
git clone <repository_url>
3.配置用户信息:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

二、基本操作

1.查看文件状态:
git status
2.添加文件到暂存区:
git add <file1> <file2> ...
3.提交更改到版本库:
git commit -m "Your commit message"
4.查看提交日志:
git log

三、分支操作

1.创建新分支:

git branch <branch_name>
2.切换到指定分支:
git checkout <branch_name>或git switch <branch_name>
3.创建并切换到新分支:
git checkout -b <new_branch_name>或git switch -c <new_branch_name>
 1732  git branch test_1  -- 创建新分支test_11733  git branch -r --查看远程分支1734  git checkout test_1 --切换到指定分支test_11735  git status 1736  git add.1737  git add README.md1738  git commit -m "Your commit message"1739  git push -u origin master  --此时推送的是master分支,README.md文件并没有修改1740  git push -u origin test_1    --此时推送的是test_1分支,README.md文件已经修改后续在gitlab会出现push request,可以手动创建merge request,并同意;

4.合并分支:
git merge <branch_name>

5.删除分支:

git branch -d <branch_name>

四、远程操作

1.查看远程仓库信息:
git remote -v
2.添加远程仓库:
git remote add <remote_name> <repository_url>
3.从远程仓库拉取更新:
git pull <remote_name> <branch_name>
4.推送本地更改到远程仓库:
git push <remote_name> <branch_name>
5.查看远程分支:
git branch -r

五、撤销和重置

1.撤销工作区的更改:
git restore <file>或git checkout -- <file>举例子:git checkout -- README.md
2.撤销暂存区的更改:
git reset HEAD <file>举例子:git reset HEAD README.md
3.回滚到之前的提交:
git reset --hard <commit_hash>

六、其他操作

1.查看修改过的文件:
git diff
2.查看分支合并图:
git log --graph --oneline --all
3.查看帮助信息:
git --help

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"git命令清单":http://eshow365.cn/6-29829-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!