1. 程式人生 > >git 命令整理

git 命令整理

文件管理 commit 文件名 nbsp 管理 需要 推送 多個 new

一、git branch:
1、創建本地分支 local_branch

git branch local_branch

2、切換到分支local_branch

git checkout local_branch

3、創建本地分支local_branch 並切換到local_branch分支

git checkout -b local_branch

4、推送本地分支local_branch到遠程分支 remote_branch並建立關聯關系

a.遠程已有remote_branch分支並且已經關聯本地分支local_branch且本地已經切換到local_branch

git push

b.遠程已有remote_branch分支但未關聯本地分支local_branch且本地已經切換到local_branch

git push -u origin/remote_branch

c.遠程沒有有remote_branch分支並,本地已經切換到local_branch

git push origin local_branch:remote_branch

5、刪除本地分支local_branch

git branch -d local_branch

6、刪除遠程分支remote_branch

git push origin :remote_branch

git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已經存在,則需要使用-M強制重命名,否則,使用-m進行重命名。

git branch -d | -D branchname 刪除branchname分支

git branch -d -r branchname 刪除遠程branchname分支


7、查看本地分支

git branch


8、查看遠程和本地分支

git branch -a

二、git 刪除文件
1. 單個刪除文件
git rm test.txt //刪除多個文件,可用空格分開文件名
git commit -m "說明" //提交
git push //提交到遠程倉庫

2. 批量刪除:
方法一:(如果是刪除當前文件夾下所有文件,方法一將刪除該空文件夾一並刪除,不會保留文件夾)

操作:(cd 到你要刪除的目錄下或者 * 可用“”文件夾名“”代替) -r 代表 recursively(遞歸)

git rm * -r

git commit -m "clear"

方法二:手動在文件管理器中刪除批量文件,然後執行命令:(如果是刪除當前文件夾下所有文件,方法二仍會保留該空文件夾)

git add .

git commit -m "clear"

最後考慮是否同步到遠程倉庫,執行:

git push




git 命令整理