1. 程式人生 > >git體驗

git體驗

cat details ppi pin perm object ocr 技術 1.0

技術分享

(1)git初始化配置
#配置用戶名
git config --global user.name "azcode"
#配置郵箱
git config --global user.email "[email protected]"
#配置gui編碼
git config --global gui.encoding utf-8
#配置status編碼
git config --global core.quotepath off
#windows配置
git config --global core.ignorecase false
#忽略換行符
git config --global core.autocrlf false
#生成ssh key pair
ssh-keygen -t rsa -C "[email protected]

/* */"
ssh key pair
cat ~/.ssh/id_rsa.pub
#將生成的key pair復制到gitlab的配置信息中

(2)將項目上傳到遠程倉庫
#進入到項目目錄並創建README.md文件
touch README.md
vim README.md
#創建.gitignore文件設定忽略規則
touch .gitignore
vim .gitignore

*.class

#package file
*.war
*.ear

#kidff3 ignore
*.orig

#maven ignore
target/

#eclipse ignore
.settings/
.project
.classpath

#idea ignore
.idea
/ /idea/ *.ipr *.iml *.iws #temp file ignore *.log *.cache *.diff *.patch *.tmp #system ignore .DS_store Thumbs.db

#初始化git倉庫
git init
Initialized empty Git repository in C:/workspace/freshman-ssh/.git/

#查看git狀態
git status
On branch master

Initial commit

Untracked files:
(use "git add <file>..." to include in what will be committed)

.gitignore
README.md
pom.xml
src/

nothing added to commit but untracked files present (use "git add" to track)

#將修改信息添加到倉庫
git add .

#再次查看狀態
git status
On branch master

Initial commit

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: .gitignore
new file: README.md
new file: pom.xml
new file: src/main/java/com/iflytek/ssh/conf/AppConfig.java
new file: src/main/java/com/iflytek/ssh/conf/AppInitializer.java
new file: src/main/java/com/iflytek/ssh/conf/HibernateConfiguration.java
new file: src/main/java/com/iflytek/ssh/controller/AppController.java
new file: src/main/java/com/iflytek/ssh/dao/AbstractDao.java
new file: src/main/java/com/iflytek/ssh/dao/EmployeeDao.java
new file: src/main/java/com/iflytek/ssh/dao/EmployeeDaoImpl.java
new file: src/main/java/com/iflytek/ssh/model/Employee.java
new file: src/main/java/com/iflytek/ssh/service/EmployeeService.java
new file: src/main/java/com/iflytek/ssh/service/EmployeeServiceImpl.java
new file: src/main/resources/application.properties
new file: src/main/resources/log4j.properties
new file: src/main/resources/message.properties
new file: src/main/webapp/WEB-INF/views/allemployees.jsp
new file: src/main/webapp/WEB-INF/views/registration.jsp
new file: src/main/webapp/WEB-INF/views/success.jsp

#確認提交並添加註釋
git commit -am ‘first commit init project‘

#添加遠程倉庫地址
git remote add origin [email protected]:qjtang/freshman-ssh.git

#查看分支信息
git branch

#將倉庫提交到遠程的master分支
git push -u origin master
The authenticity of host ‘git.coding.net (116.211.78.90)‘ can‘t be established.
RSA key fingerprint is SHA256:jok3FH7q5LJ6qvE7iPNehBgXRw51ErE77S0Dn+Vg/Ik.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘git.coding.net,116.211.78.90‘ (RSA) to the list of known hosts.
To git.coding.net:qjtang/freshman-ssh.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to [email protected]:qjtang/freshman-ssh.git‘
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull ...‘) before pushing again.
hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.

#需要先從遠程倉庫拉取
git pull
warning: no common commits
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
From git.coding.net:qjtang/freshman-ssh
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> master

#再次提交提示遠程倉庫比本地倉庫版本新
git push -u origin master
To git.coding.net:qjtang/freshman-ssh.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to [email protected]:qjtang/freshman-ssh.git‘
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull ...‘) before pushing again.
hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.

#直接覆蓋遠程倉庫強制提交
git push -u -f origin master
Counting objects: 36, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (36/36), 11.12 KiB | 0 bytes/s, done.
Total 36 (delta 2), reused 0 (delta 0)
To git.coding.net:qjtang/freshman-ssh.git
+ 49234d0...4fc84f9 master -> master (forced update)
Branch master set up to track remote branch master from origin.

#查看所有分支信息
git branch -r
origin/master

#查看當前分支信息
git branch
* master

#新建一個v1.0的分支並切換到該分支,從master分支檢出該分支
git checkout -b v1.0 origin/master
Switched to a new branch ‘v1.0‘
Branch v1.0 set up to track remote branch master from origin.

#查看當前分支信息
git branch
master
* v1.0

#將新建分支提交到遠程倉庫
git push origin HEAD -u
Total 0 (delta 0), reused 0 (delta 0)
To git.coding.net:qjtang/freshman-ssh.git
* [new branch] HEAD -> v1.0
Branch v1.0 set up to track remote branch v1.0 from origin.

git體驗