1、本地操作
- Linux安装git:yum install git
- 查看git版本 git version
- 查看git设置 git config --list
- 设置git属性 git config --global
- 初始化git仓库:git init
- 初始化git用户邮箱:git config --global user.email “rice_van@email.com”
- 初始化git用户姓名:git config --global user.name “rice_van”
- 添加指定文件到暂存区:git add filename.txt
- 添加多个文件到暂存区:git add filename1.txt filename2.txt …
- 添加当前目录的所有文件到暂存区:git add.
- 添加指定目录到暂存区,包括其子目录: git add dir
- 提交暂存区修改到仓库区:git commit -m “change messages”
- 提交暂存区修改到仓库区,并合并到上次修改:git commit --amend -m “message”
- 查看某次提交的具体信息:git show commit_id
- 查看版本库状态:git status
- 查看工作区文件修改内容:git diff filename.txt
- 查看暂存区文件修改内容:git diff --cached filename.txt
- 查看版本库修改记录:git log
- 查看版本库简洁记录:git log --pretty=oneline
- 查看所有的命令记录:git reflog
- 查看某个文件的修改信息:git log -p filename.txt
- 查看某人的提交记录信息:git log --author=someone
2、版本管理
版本库提交流程:
- 第一步是用git add把文件添加进去,实际上就是把文件修改添加到暂存区;
- 第二步是用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支。
- 每次修改,如果不用git add到暂存区,那就不会加入到commit中
- 第一次修改 -> git add -> 第二次修改 -> git add -> git commit
- HEAD表示版本库的当前版本
- HEAD^表示上一版本,上上版本HEAD^^
- 前100次版本HEAD~100
- 回退最新commit提交:git reset --hard HEAD^ (即回到此版本的前一版本)
- 回到指定commit版本:git reset --hard commit_id (同时重置暂存区和工作区)
- 撤销暂存区修改:git reset HEAD filename.txt (修改内容放回到工作区)
- 撤销暂存区修改:git checkout filename(修改内容放回到工作区)
- 撤销暂存区所有修改:git checkout . (修改内容放回到工作区)
- 回退暂存区到指定commit:git checkout commit_id
- 撤销工作区修改:git checkout -- filename.txt
- 回退本地误删文件:git checkout --filename.txt
- 删除版本库文件:
git rm filename.txt
git commit -m “remove filename.txt” - 停止追踪指定文件,但该文件会保留在工作区:git rm --cached filename.txt
- 改名文件,并且将这个改名放入暂存区:git mv file-original file-renamed
3、远端仓库
- 生成ssh秘钥:ssh-keygen -t rsa -C “xxxxxx@email.com”
- 克隆远端仓库到本地:git clone git@github.com:xxxxx/learngit.git
- 本地关联远程仓库:git remote add origin git@gitee.com:xxxxx/learngit.git
- 查看远端仓库:git remote
- 查看远程仓库信息:git remote -v
- 查看远程某个仓库信息:git remote show branchname
- 删除远端关联关系:git remote rm origin
- 本地仓库推送远程仓库:git push origin branchname
- 本地仓库推送远程仓库:git push -u origin branchname
- 推送到远端指定分支:git push origin originbranchname
- 推送本地分支与远端分支不同名时:git push origin HEAD:branchname (远端名)
- 设置本地分支对应到远端指定分支:git branch --set-upstream-to=origin/branchname branchname
- 抓取远程分支到本地:git checkout -b branchname origin/branchname
- 远端修改更新本地:git pull
- 远端分支更新本地:git pull origin branchname
尽量保持本地分支名与远端分支名一致
fork参考:https://blog.csdn.net/qq_36412715/article/details/122121445
fetch参考:https://blog.csdn.net/QH_JAVA/article/details/77969010
rebase参考:https://waynerv.com/posts/git-rebase-intro/
4、分支管理
- 查看本地所有分支:git branch
- 查看本地和远端所有分支:git branch -a
- 创建分支:git branch branchname
- 删除分支:git branch -d branchname
- 强行删除为合并分支:git branch -D branchname
- 切换分支:git swtich branchname
- 切换分支:git checkout branchname
- 创建并切换分支:git swtich -c branchname
- 创建并切换分支:git checkout -b branchnme
- 合并到指定分支到当前分支:git merge branchname
- 禁用Fast Forward方式合并:git merge --no-ff -m “messages” branchname (删除分支后可看合并历史)
- 查看分支合并图:git log --graph
- 查看分支合并图简易:git log --graph --pretty=oneline --abbrev-commit
- 复制commit到当前分支:git cherry-pick commitid
5、缓存stash
- 缓存修改:git stash
- 缓存并标记:git stash -m “issue-01-2023.03.20:57”
- 缓存列表:git stash list
- 应用缓存:git stash apply
- 删除缓存:git stash drop
- 应用并删除:git stash pop
- 应用某一缓存:git stash apply stash@{4}
- 清理工作区:
git stash
git clean -dxf; git checkout .; git reset --hard FETCH_HEAD; git pull
git stash pop
6、标签管理
- 标签作用:标记commit,快速查看重要提交节点
- 添加标签默认添加到当前分支的最新commit:git tag v1.0
- 添加标签到指定commit:git tag v2.0 commitid
- 添加标签与说明信息:git tag -a v3.0 -m “version 3.0 released”
- 查看所有标签:git tag
- 查看详细标签:git show v2.0
- 删除标签:git tag -d v3.0
- 推送标签到远程:git push origin v1.0
- 推送所有标签:git push origin --tags
- 删除远端标签:
git tag -d v1.0
git push origin :refs/tags/v1.0
7、参考教程
8、示例代码
# 安装
[root@ecs-xxx ~]# yum install git
Loaded plugins: fastestmirror
...
Complete!
[root@ecs-xxx ~]# git version
git version 1.8.3.1
[root@ecs-xxx ~]# whereis git
git: /usr/bin/git /usr/share/man/man1/git.1.gz
# 建仓
[root@ecs-xxx home]# mkdir learngit
[root@ecs-xxx home]# cd learngit
[root@ecs-xxx learngit]# pwd
/home/learngit
[root@ecs-xxx learngit]# git init
Initialized empty Git repository in /home/learngit/.git/
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# ls -a
. .. .git
# 设置默认身份
[root@ecs-xxx learngit]# git config --global user.email "xxxxxx@email.com"
[root@ecs-xxx learngit]# git config --global user.name "xxxxxx"
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git config --list
user.email=xxxxxx@email.com
user.name=xxxxx
remote.origin.url=git@gitee.com:xxxxx/learngit.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
# 提交本地仓库
[root@ecs-xxx learngit]# touch readme.txt
[root@ecs-xxx learngit]# vim readme.txt
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
[root@ecs-xxx learngit]# git add readme.txt
[root@ecs-xxx learngit]# git commit -m 'wrote a readme file.'
[master (root-commit) af264a5] wrote a readme file.
1 file changed, 2 insertions(+)
create mode 100644 readme.txt
# 查看本地仓库状态:已修改未添加缓存区,提示Changes not staged
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
[root@ecs-xxx learngit]# vim readme.txt
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
# 查看本地和仓库差异内容
[root@ecs-xxx learngit]# git diff
diff --git a/readme.txt b/readme.txt
index 1a0762b..68fe139 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,3 @@
Git is a version control system.
xf
+Git is free software.
# 查看本地仓库状态:已添加缓存区,提示Changes to be committed
[root@ecs-xxx learngit]# git add readme.txt
[root@ecs-xxx learngit]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: readme.txt
# 查看本地仓库状态:已提交仓库,提示working directory clean
[root@ecs-xxx learngit]# git commit -m "add new line"
[master 910aa81] add new line
1 file changed, 1 insertion(+)
[root@ecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
# 查看日志信息
[root@ecs-xxx learngit]# git log
commit af264a5ada2e059ad822d7121fa2e595129198de
Author: xxxxxx <xxxxxx@email.com>
Date: Thu Mar 2 10:01:05 2023 +0800
:
Date: Thu Mar 2 10:06:21 2023 +0800
add system time
commit 910aa81c9bade65244b9ba43a74f225dc931f22e
Author: xxxxxx <xxxxxx@email.com>
Date: Thu Mar 2 10:03:55 2023 +0800
add new line
commit af264a5ada2e059ad822d7121fa2e595129198de
Author: xxxxxx <xxxxxx@email.com>
Date: Thu Mar 2 10:01:05 2023 +0800
wrote a readme file.
[1]+ Stopped git log
# 查看简易日志信息
[root@ecs-xxx learngit]# git log --pretty=oneline
331832aa56734d0f34517fd246ceb32b32ed20a2 add system time
910aa81c9bade65244b9ba43a74f225dc931f22e add new line
af264a5ada2e059ad822d7121fa2e595129198de wrote a readme file.
# 撤销最新提交,重置本地到前一版本
[root@ecs-xxx learngit]# git reset --hard HEAD^
HEAD is now at 910aa81 add new line
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
[root@ecs-xxx learngit]# git log
commit 910aa81c9bade65244b9ba43a74f225dc931f22e
Author: xxxxxx <xxxxxx@email.com>
Date: Thu Mar 2 10:03:55 2023 +0800
add new line
commit af264a5ada2e059ad822d7121fa2e595129198de
Author: xxxxxx <xxxxxx@email.com>
Date: Thu Mar 2 10:01:05 2023 +0800
wrote a readme file.
[root@ecs-xxx learngit]#
# 新增文件,提示:Untracked files
[root@ecs-xxx learngit]# touch license.txt
[root@ecs-xxx learngit]# vim license.txt
[root@ecs-xxx learngit]# git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# license.txt
nothing added to commit but untracked files present (use "git add" to track)
# 查看本地仓库状态:添加新文件且有修改
[root@ecs-xxx learngit]# vim readme.txt
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# license.txt
no changes added to commit (use "git add" and/or "git commit -a")
# 未提交到缓存区时,撤销本地修改:git checkout -- filename.txt
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
My stupid boss.
[root@ecs-xxx learngit]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@ecs-xxx learngit]# git checkout -- readme.txt
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
# 已到暂存区的修改,先撤销暂存区到工作区:get reset HEAD filename.txt,再撤销工作区修改:git checkout -- filename.txt
[root@ecs-xxx learngit]# vi readme.txt
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
Fuck!!
[root@ecs-xxx learngit]# git add readme.txt
[root@ecs-xxx learngit]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: readme.txt
#
[root@ecs-xxx learngit]# git reset HEAD readme.txt
Unstaged changes after reset:
M readme.txt
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
Fuck!!
[root@ecs-xxx learngit]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@ecs-xxx learngit]# git checkout -- readme.txt
[root@ecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
[root@ecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
# 撤销本地删除:git checkout -- test.txt
[root@ecs-xxx learngit]# rm test.txt
rm: remove regular empty file ‘test.txt’? y
[root@ecs-xxx learngit]# ls
license.txt readme.txt
[root@ecs-xxx learngit]# git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@ecs-xxx learngit]# git checkout -- test.txt
[root@ecs-xxx learngit]# ls
license.txt readme.txt test.txt
# 查看本地操作记录
[root@ecs-xxx learngit]# git reflog
6aca85e HEAD@{0}: rebase finished: returning to refs/heads/master
6aca85e HEAD@{1}: pull --rebase origin master: add test.txt
1149b68 HEAD@{2}: pull --rebase origin master: add new file license.txt
283dd5f HEAD@{3}: pull --rebase origin master: add system time
92808ba HEAD@{4}: pull --rebase origin master: add new line
2b29c43 HEAD@{5}: pull --rebase origin master: wrote a readme file.
58bbad5 HEAD@{6}: checkout: moving from master to 58bbad55beedbb8e07a334b18dcf0694ab6fa291^0
cd18992 HEAD@{7}: commit: add test.txt
40b3936 HEAD@{8}: commit: add new file license.txt
331832a HEAD@{9}: reset: moving to 331832
910aa81 HEAD@{10}: reset: moving to HEAD^
331832a HEAD@{11}: commit: add system time
910aa81 HEAD@{12}: commit: add new line
af264a5 HEAD@{13}: commit (initial): wrote a readme file.
# 生成ssh秘钥
[root@ecs-xxx ~]# ssh-keygen -t rsa -C "xxxxxx@email.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX email@email.com
The key's randomart image is:
+---[RSA 2048]----+
+----[SHA256]-----+
[root@ecs-xxx ~]# ls -a
. .bash_history .bash_profile .cshrc .history .pki .tcshrc
.. .bash_logout .bashrc .gitconfig mirrors_source.sh .ssh .viminfo
[root@ecs-xxx ~]# cd .ssh
[root@ecs-xxx .ssh]# ls
authorized_keys id_rsa id_rsa.pub
# 关联远端仓库
[root@ecs-xxx learngit]# git remote add origin git@gitee.com:xxxxx/learngit.git
[root@ecs-xxx learngit]# git remote -v
origin git@gitee.com:xxxxx/learngit.git (fetch)
origin git@gitee.com:xxxxx/learngit.git (push)
# 更新本地代码
[root@ecs-xxx learngit]# git pull
warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From gitee.com:xxxxx/learngit
* [new branch] develop -> origin/develop
* [new branch] feature -> origin/feature
* [new branch] master -> origin/master
* [new branch] release -> origin/release
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
# 提交远端仓库
[root@ecs-xxx learngit]# git push -u origin master
Warning: Permanently added the ECDSA host key for IP address '212.64.63.190' to the list of known hosts.
To git@gitee.com:xxxxx/learngit.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@gitee.com:xxxxx/learngit.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git pull --rebase origin master
From gitee.com:xxxxx/learngit
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: wrote a readme file.
Applying: add new line
Applying: add system time
Applying: add new file license.txt
Applying: add test.txt
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git push -u origin master
Counting objects: 17, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (16/16), 1.32 KiB | 0 bytes/s, done.
Total 16 (delta 6), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To git@gitee.com:xxxxx/learngit.git
58bbad5..6aca85e master -> master
Branch master set up to track remote branch master from origin.
# 创建本地分支&切换分支
[root@ecs-xxx learngit]# git branch
* master
[root@ecs-xxx learngit]# git checkout -b ecs_dev
Switched to a new branch 'ecs_dev'
[root@ecs-xxx learngit]# git branch
* ecs_dev
master
[root@ecs-xxx learngit]# git checkout master
Switched to branch 'master'
[root@ecs-xxx learngit]# git branch
ecs_dev
* master
[root@ecs-xxx learngit]# git branch ecs-dev2
[root@ecs-xxx learngit]# git branch
ecs-dev2
* ecs_dev
master
[root@ecs-xxx learngit]# git switch ecs-dev2
Switched to branch 'ecs-dev2'
[root@ecs-xxx learngit]# git branch
* ecs-dev2
ecs_dev
master
# 合并分支修改
[root@ecs-xxx learngit]# cat license.txt
this is a license.
this is PC change.
add from ecs branch dev.
[root@ecs-xxx learngit]# vim license.txt
[root@ecs-xxx learngit]# cat license.txt
this is a license.
this is PC change.
add from ecs branch dev.
add from ecs branch dev2.
[root@ecs-xxx learngit]# git add license.txt
[root@ecs-xxx learngit]# git commit -m "modify license from ecs dev2"
[ecs-dev2 0d64648] modify license from ecs dev2
1 file changed, 1 insertion(+)
[root@ecs-xxx learngit]# git status
On branch ecs-dev2
nothing to commit, working tree clean
[root@ecs-xxx learngit]# git switch master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
[root@ecs-xxx learngit]# git merge ecs-dev2
Updating 3100ae8..0d64648
Fast-forward
license.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[root@ecs-xxx learngit]# cat license.txt
this is a license.
this is PC change.
add from ecs branch dev.
add from ecs branch dev2.
# 删除本地分支
[root@ecs-xxx learngit]# git branch -d ecs-dev2
Deleted branch ecs-dev2 (was 0d64648).
[root@ecs-xxx learngit]# git branch -d ecs_dev
Deleted branch ecs_dev (was 0b9e768).
[root@ecs-xxx learngit]# git branch
* master
# 解决冲突
[root@ecs-xxx learngit]# git merge dev
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.
[root@ecs-xxx learngit]# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
[root@ecs-xxx learngit]# cat readme.txt
<<<<<<< HEAD
ADD feature2 branch master.
=======
ADD feature1.
>>>>>>> dev
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
[root@ecs-xxx learngit]# vim readme.txt
[root@ecs-xxx learngit]# cat readme.txt
Add feature2 branch master.
Add featuer1 branch dev.
Git is a version control system.
xf
Git is free software.
2023/3/2
Git has a mutable index called stage.
[root@ecs-xxx learngit]# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
[root@ecs-xxx learngit]# git diff
diff --cc readme.txt
index 7c42656,65d11a6..0000000
--- a/readme.txt
+++ b/readme.txt
@@@ -1,4 -1,4 +1,6 @@@
- ADD feature2 branch master.
-ADD feature1.
++
++Add feature2 branch master.
++Add featuer1 branch dev.
Git is a version control system.
xf
Git is free software.
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git add readme.txt
[root@ecs-xxx learngit]# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: readme.txt
[root@ecs-xxx learngit]# git commit -m "fix conflict"
[master 61228c2] fix conflict
[root@ecs-xxx learngit]# git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
# 查看日志图
[root@ecs-xxx learngit]# git log --graph
* commit 61228c24f3c350429ff7de39de31e60847a1cf50 (HEAD -> master)
|\ Merge: 8b8e26d 238745a
| | Author: xxxxxx <xxx@email.com>
| | Date: Thu Mar 2 20:25:37 2023 +0800
| |
| | fix conflict
| |
| * commit 238745a3d84c69677a69835b00852a2c7550b0fc (dev)
| | Author: xxxxxx <xxx@email.com>
| | Date: Thu Mar 2 20:15:43 2023 +0800
| |
| | branch dev add featuer1
| |
* | commit 8b8e26d0c24c9ba0fa5eee2125ed43f6a5f4a2ab
|/ Author: xxxxxx <xxx@email.com>
| Date: Thu Mar 2 20:17:46 2023 +0800
|
| add featuer2 from master
|
* commit 0d646484989b9f76745a18bd6955f8c79e0db9aa (origin/master)
| Author: xxxxxx <xxx@email.com>
| Date: Thu Mar 2 20:09:48 2023 +0800
|
| modify license from ecs dev2
:...skipping...
* commit 61228c24f3c350429ff7de39de31e60847a1cf50 (HEAD -> master)
|\ Merge: 8b8e26d 238745a
| | Author: xxxxxx <xxx@email.com>
| | Date: Thu Mar 2 20:25:37 2023 +0800
| |
| | fix conflict
| |
| * commit 238745a3d84c69677a69835b00852a2c7550b0fc (dev)
| | Author: xxxxxx <xxx@email.com>
| | Date: Thu Mar 2 20:15:43 2023 +0800
| |
| | branch dev add featuer1
| |
* | commit 8b8e26d0c24c9ba0fa5eee2125ed43f6a5f4a2ab
|/ Author: xxxxxx <xxx@email.com>
| Date: Thu Mar 2 20:17:46 2023 +0800
|
| add featuer2 from master
|
* commit 0d646484989b9f76745a18bd6955f8c79e0db9aa (origin/master)
| Author: xxxxxx <xxx@email.com>
| Date: Thu Mar 2 20:09:48 2023 +0800
|
| modify license from ecs dev2
|
* commit 0b9e7686a67b5b0767c3a733aacce134c22b1494
| Author: xxxxxx <xxx@email.com>
| Date: Thu Mar 2 19:35:39 2023 +0800
|
| license.txt modify from ecs
|
* commit 3100ae8311375169803a874f5f6cd5ba99741b70
| Author: xxx 00585232 <xxx@email.com>
| Date: Thu Mar 2 11:26:47 2023 +0800
|
| modify liscens.txt from pc
|
* commit 6aca85ed747b7f239f1c25ea9cd815a848b7b335
[3]+ Stopped git log --graph
[root@ecs-xxx learngit]#
# stash用法
[root@ecs-xxx learngit]# cat test.txt
[root@ecs-xxx learngit]# git branch
dev
* master
[root@ecs-xxx learngit]# vim test.txt
[root@ecs-xxx learngit]# cat test.txt
stash test.
[root@ecs-xxx learngit]# git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
[root@ecs-xxx learngit]# git stash -m "modify test.txt"
Saved working directory and index state On master: modify test.txt
[root@ecs-xxx learngit]# git stash list
stash@{0}: On master: modify test.txt
[root@ecs-xxx learngit]# git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git switch dev
Switched to branch 'dev'
[root@ecs-xxx learngit]# vim readme.txt
[root@ecs-xxx learngit]# git add readme.txt
[root@ecs-xxx learngit]# git commit -m "dev is diff"
[dev 601592f] dev is diff
1 file changed, 1 insertion(+)
[root@ecs-xxx learngit]# git push origin dev
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 298 bytes | 298.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:xxxxxx/learngit.git
238745a..601592f dev -> dev
[root@ecs-xxx learngit]# git switch master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
[root@ecs-xxx learngit]# git stash list
stash@{0}: On master: modify test.txt
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git stash apply stash@{0}
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
# cherry-pick用法
[root@ecs-xxx learngit]# git switch dev
Switched to branch 'dev'
[root@ecs-xxx learngit]# git cherry-pick bf959b0
[dev 4fe0a2f] ok
Date: Thu Mar 2 20:55:53 2023 +0800
1 file changed, 1 insertion(+)
[root@ecs-xxx learngit]# git status
On branch dev
nothing to commit, working tree clean
[root@ecs-xxx learngit]# git push origin dev
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 266 bytes | 266.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:xxxxxx/learngit.git
601592f..4fe0a2f dev -> dev
# 抓取远程分支到本地
[root@ecs-xxx learngit]# git checkout -b dev origin/dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
Switched to a new branch 'dev'
[root@ecs-xxx learngit]# git branch
master
* dev
# 设置本地分支对应到远端指定分支
[root@ecs-xxx learngit]# git switch master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
[root@ecs-xxx learngit]# git branch --set-upstream-to=origin/dev master
Branch 'master' set up to track remote branch 'dev' from 'origin'.
# 本地分支与远端分支名不同时
[root@ecs-xxx learngit]# git push
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:dev
To push to the branch of the same name on the remote, use
git push origin HEAD
To choose either option permanently, see push.default in 'git help config'.
[root@ecs-xxx learngit]# git push origin dev
Everything up-to-date
[root@ecs-xxx learngit]# git push origin HEAD:dev
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 298 bytes | 298.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:xxxxxx/learngit.git
4fe0a2f..58cbebb HEAD -> dev
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git branch --set-upstream-to=origin/master master
Branch 'master' set up to track remote branch 'master' from 'origin'.
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]#
[root@ecs-xxx learngit]# git branch --set-upstream-to=origin/dev dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
[root@ecs-xxx learngit]#