【学习笔记】Git常用命令

Git常用命令

1. git init (初始化一个新的Git仓库)

在项目目录中运行此命令,以便开始跟踪文件更改。

git init

2. git clone [url] (克隆远程仓库到本地计算机)

[url]替换为远程仓库的URL。

git clone https://github.com/user/repo.git

3. git status (查看当前工作区的状态)

查看已修改但未提交的文件。

git status

4. git add [file] (将文件添加到暂存区)

[file]替换为要添加的文件名。如果使用git add .,则会添加所有更改过的文件。

git add file.txt

5. git commit -m “commit message” (提交暂存区中的更改)

附上一条描述性的提交信息。

git commit -m "Add new feature"

6. git log (查看提交历史记录)

git log

7. git diff (查看工作区与上次提交之间的代码差异)

git diff

8. git remote -v (查看已配置的远程仓库及其URL)

git remote -v

9. git remote add [remote-name] [url] (添加一个新的远程仓库)

[remote-name]替换为远程仓库的名称,如origin,将[url]替换为远程仓库的URL。

git remote add origin https://github.com/user/repo.git

10. git push [remote-name] [branch-name] ( 将本地分支推送到远程仓库)

[remote-name]替换为远程仓库的名称,如origin,将[branch-name]替换为要推送的分支名称,如main

git push origin main

11. git pull [remote-name] [branch-name] (从远程仓库拉取最新的更改并合并到本地分支)

[remote-name]替换为远程仓库的名称,如origin,将[branch-name]替换为要拉取的分支名称,如main

git pull origin main

12. git fetch [remote-name] (从远程仓库获取最新的更改)

不进行合并。将[remote-name]替换为远程仓库的名称,如origin

git fetch origin

13. git branch (查看本地分支列表)

git branch

14. git checkout [branch-name] ( 切换到另一个分支或恢复工作树文件)

[branch-name]替换为要切换到的分支名称。

git checkout feature-branch

15. git merge [branch-name] (将指定的分支合并到当前分支)

将[branch-name]替换为要合并的分支名称。

git merge feature-branch
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值