GIT Manual


#GIT Create Project

使用说明

修改eclipse 的 token

在这里插入图片描述

github 生产token

Settings
/
Developer Settings
/
Personal access tokens (classic)

事先pull,push后synch

因为IDE的git工具只比较最新修改和最后一次pull的版本,每次push或者commit前需要解决冲突,所以要把服务器上最新版本pull下来,本地解决冲突,然后再commit。commit后一定要synch,或者服务器上的最新版本。
为什么一定要synch,防止解决本地冲突的时候不是和最新版本进行比较,这样即使解决冲突push上去,也不是最新版本。synch可以保证本地与服务器同步。
即使提交之前pull到最新版本,但是在解决冲突的过程中,有其他人也会push。所以,push之后的synch非常重要。

创建Project

本地初始化

把当前文件夹变成Git仓库,成功后多一个git文件夹,但是.gitignore是maven的文件。

$ git init
Initialized empty Git repository in D:/workspace/javaspace/erp/.git/

在这里插入图片描述

查看当前文件夹下的文件管理状态

untrcked files显示所有不受git管理的文件。

$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore
        .mvn/
        mvnw
        mvnw.cmd
        pom.xml
        src/
nothing added to commit but untracked files present (use "git add" to track)

把所有的文件添加到本地仓库

$ git add .
$ git commit -m "this is frist commit"

脚本如下:

echo "# openerp" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/develperofbamboobook/openerp.git
git push -u origin main

把本地文件push到服务器的另一个分支

先切换到提交的目录下
$ git checkout master
如果當前分支與多個主機存在追蹤關係,則可以使用-u選項指定一個默認主機,這樣後麵就可以不加任何參數使用git push。
$ git push -u origin master

最简单的一次提交

在本分支下提交

$ git status

参考下文件状态

$ git add .

提交所有

$ git commit -m ‘log’

写备注并提交到本地库

$ git push

提交到服务器

GIT Command

Distributed Version Control System,分布式版本控制系统,Such as Git、Mercurial、Bazaar、Darcs。镜像
客户端并提取最新版本的快照,把代码仓库完整地镜像下来。如果服务器发生故障,可以通過任何一个镜像出来的本地仓库恢复。

安装

Download for Windows
在这里插入图片描述
从源码进行安装

C:\>winget install --id Git.Git -e --source winget
已找到 Git [Git.Git] 版本 2.37.3
此应用程序由其所有者授权给你。
  ██████████████████████████████  47.0 MB / 47.0 MB
已成功验证安装程序哈希
正在启动程序包安装...
已成功安装

查看版本

PS C:\> git --version
git version 2.32.0.windows.2
或者
C:\>git -v
git version 2.37.3.windows.1

查看git安装路径

C:\Windows\system32>where git
D:\codetool\git\git.exe

查看、切換目錄

$ cd ..
$ pwd

查看所有本地分支

并输出最后一次提交备注

$ git branch -v
  dev    bb059b0 first commit
* master bb059b0 first commit

查看本地和远程跟踪分支

输出显示了存储库中的所有本地和远程跟踪分支名称

$ git branch -a
  master
* test
  remotes/origin/master

在这里插入图片描述

$ git branch
  master
* test

在这里插入图片描述

$ git branch -v -v
  master cff658a [origin/master] 按版本管理
* test   cff658a [origin/master] 按版本管理

檢出並創建project

  1. 默認master branch,全部檢出,本地切換
$ git clone #git url

2.檢出指定branch,其它branch在本地被Track

git clone --branch <branchname> <remote-repo-url>

or

git clone -b <branchname> <remote-repo-url>

3.檢出指定branch,其它branch不被Track

git clone --branch <branchname> --single-branch <remote-repo-url>

or

git clone -b <branchname> --single-branch <remote-repo-url>

eclipse import project

在这里插入图片描述

重命名

git branch -m 和 git branch -M 是用来移动和重命名分支的。 类似 -c 参数,对于参数 -m,其只会在目标不存在的时候进行移动和重命名,-M 参数则不管目标是否存在都会移动和重命名。 -m -f 可以实现和 -M 相同的效果。

git checkout test
//把test分支改成newtest
git branch -m newtest
git branch
# * dev
#   master
#   newtest

切換brancher

在project的目錄下切換brancher

$ cd *rap*d
$ git checkout develop
Switched to a new branch 'develop'
Branch 'develop' set up to track remote branch 'develop' from 'origin'

或者

git switch branch name

创建branch

$ git branch master

切换branch

$ git checkout master
Switched to branch 'master'

創建并切换到brancher

## 在本地創建,push時在遠程創建
$ git checkout -b test

删除本地分支

不能在Branch test 下刪除,必須切換到其它目錄,如master目錄

$ git branch -d test
Deleted branch test (was cff658a).

git branch -D branch_name   #強制刪除

合併&&提交,新Brancher合併

$ git merge develop    # Local Repository
git push --set-upstream origin test

查看project狀態,與remote repository差異

$ git status
$ git pull     # 下載服務器端file 
or
$ git fetch      v1.8.4 later

贮藏与清理 ([TODO]

TODO

$ git stash

pop [Stashing and Cleaning]

TODO

清屏

$ clear

git branch --unset-upstream 刪除跟踪信息

Git告诉您可以使用删除跟踪信息–unset-upstream。这将清除branch.source.origin和branch.source.merge,并停止警告。

$ git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

git push --set-upstream origin master

提交並在遠程創建master branch

$ git push --set-upstream origin master
Everything up-to-date
Branch 'master' set up to track remote branch 'master' from 'origin'.

建立追蹤Track(Local to Remote)

本地庫與遠程庫的對應關係,即遙控器

$ git branch --set-upstream-to=origin/master
Branch 'test' set up to track remote branch 'master' from 'origin'.

修改登錄賬戶

remote: HTTP Basic: Access denied,置空後,重新設置Git客戶端的賬號

$ git config --system --unset credential.helper

Github 客户端

Focus on what matters instead of fighting with Git. Whether you’re new to Git or a seasoned user, GitHub Desktop simplifies your development workflow.
在这里插入图片描述

Eclipse

修改URL

在这里插入图片描述

修改password

右鍵項目,選擇team
在这里插入图片描述

在这里插入图片描述

從服務器全部替換本地

在这里插入图片描述
在这里插入图片描述

VS studio

Please clean your repository working tree before checkout

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值