git command

git command



git global setup

git config --global user.name "user name"
git config --global user.email "user@main.com"

git config --list


create a local new repository

cd existing_folder
git init
git add file (more direcotry or file path) (git add . to add all)
git commint -m "submit log"

create a repository via clone

git clone [git repository url]

modify remote repository url

git remote set-url origin
or
git remote rm origin
git remote add origin

查看分支

查看本地分支情况 git branch -a

只查看远程仓库分支情况 git branch -r

重命名分支

本地分支a重命名为b git branch -m a_name b_name

创建分支

创建本地分支 git branch 分支名
切换本地分支 git checkout 分支名

从已有的分支 创建新的分支,并切换到新的分支 git checkout -b 分支名

删除分支

删除本地分支 git branch -d 本地分支名
删除远程分支 git push origin --delete 远程分支名

删除远程旧分支,并push新分支
git push origin 本地分支名称:远程旧分支名 远程新分支名

拉取远程分支,并创建本地分支

git fetch origin
git checkout -b 本地分支名 origin/远端分支名

将本地仓库代码提交到远程仓库

git push origin current_branch
将当前分支推送到origin主机(在远程主机新建分支)

git push -u origin haha
将本地的haha分支推送到远程origin主机(远程主机没有haha分支,则新建)

git push -u origin main
加了-u,指定默认主机,以后的push, 可以直接用git push 代替git push origin main

将当前分支推送到origin主机的remote_branch分支,常用
git push -u origin local_branch origin/remote_branch

git push origin 本地分支名:远端分支名
将本地某个分支提交到远程某个分支


回退

git checkout modify_file
git checkout .

git reset --hard origin/main
git reset --hard HEAD^
git reset --hard last_commint_id

git reset --mixed last_commint_id then git checkout .

git add撤销
git status 查看add的文件
git reset HEAD 上一次add 的文件全部撤销
git reset HEAD file_path 对某个文件进行撤销

log

git log -2
git log -n
输出最后提交的n条log

git show commint_id

删除没有 git add的文件

git clean -n file/directory 显示可以删除的文件
git clean -f file 删除文件
git clean -fd file/directory 删除文件和目录



git 生成补丁

git diff ./ > debug_code.patch
打补丁:
git apply debug_code.patch
patch -p1 < debug_code.patch



create a new repository

git clone git-repository-url
cd repository
git switch -c master
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master


push an existing folder

cd existing_folder
git init --initial-branch=master
git remote add origin git-repository-url
git add .
git commit -m "Initial commit"
git push -u origin master


push an existing Git repository

cd existing_repo
git remote rm origin
git remote rename origin old-origin
git remote add origin git-repository-url
git push -u origin --all
git push -u origin --tags



git clone repo -b branch --depth=1



Git进行代码Branch merge

git merge other_branch
git cherry-pick <commit_hash>
reference:
如何利用Git进行代码Branch mergehttps://www.cnblogs.com/FireLife-Cheng/p/18332309



learngitbranching

https://learngitbranching.js.org/



posted @   王阳开  阅读(1974)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
点击右上角即可分享
微信分享提示