广州网站建设 骏域,wordpress 萌化主题,拓者网室内设计官网app,实验一 电子商务网站建设与维护Git1、本地操作2、版本管理3、远端仓库4、分支管理5、缓存stash6、遗留rebase7、标签管理8、解决冲突9、参考教程10、示例代码1、本地操作
Linux安装git#xff1a;yum install git查看git版本 git version查看git设置 git config --list设置git属性 git config --global初始…
Git1、本地操作2、版本管理3、远端仓库4、分支管理5、缓存stash6、遗留rebase7、标签管理8、解决冲突9、参考教程10、示例代码1、本地操作
Linux安装gityum install git查看git版本 git version查看git设置 git config --list设置git属性 git config --global初始化git仓库git init初始化git用户邮箱git config --global user.email “rice_vanemail.com”初始化git用户姓名git config --global user.name “rice_van”添加到仓库git add filename.txt提交到仓库git commit -m “change messages”查看仓库状态git status查看工作区修改区别git diff查看工作区文件区别git diff HEAD – filename.txt查看版本记录git log查看简洁记录git log --prettyoneline查看命令记录git reflog
2、版本管理 版本库提交流程 第一步是用git add把文件添加进去实际上就是把文件修改添加到暂存区第二步是用git commit提交更改实际上就是把暂存区的所有内容提交到当前分支。 每次修改如果不用git add到暂存区那就不会加入到commit中第一次修改 - git add - 第二次修改 - git add - git commit HEAD表示当前版本HEAD^表示上一版本上上版本HEAD^^前100次版本HEAD~100 回退最新提交git reset --hard HEAD^ 即回到此版本的前一版本回到指定版本git reset --hard commit_id撤销暂存区修改修改内容放回到工作区git rest HEAD filename.txt撤销工作区修改git checkout -- filename.txt回退本地误删文件git checkout --filename.txt删除仓库文件 git rm filename.txt git commit -m “remove filename.txt”
3、远端仓库
生成ssh秘钥ssh-keygen -t rsa -C “xxxxxxemail.com”克隆远端仓库到本地git clone gitgithub.com:xxxxx/learngit.git本地关联远程仓库git remote add origin gitgitee.com:xxxxx/learngit.git查看远端仓库git remote查看远程仓库信息git remote -v删除远端关联关系git remote rm origin本地修改推送远程仓库git push origin master本地修改推送远程仓库git push -u origin master推送到远端指定分支git push origin originbranchname抓取远程分支到本地git checkout -b branchname origin/branchname设置本地分支对应到远端指定分支git branch --set-upstream-toorigin/branchname branchname本地分支与远端分支名不同时git push origin HEAD:branchname (远端名) 尽量保持本地分支名与远端分支名一致 4、分支管理
查看所有分支git branch创建分支git branch branchname删除分支git branch -d branchname强行删除为合并分支git branch -D branchname切换分支git swtich branchname创建并切换分支git swtich -c branchname合并到指定分支到当前分支git merge branchname禁用Fast Forward方式合并git merge --no-ff -m “messages” branchname 删除分支后可看合并历史查看分支合并图git log --graph查看分支合并图简易git log --graph --prettyoneline --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}
6、遗留rebase
7、标签管理
标签作用标记commit快速查看重要提交节点添加标签默认添加到当前分支的最新commitgit tag v1.0添加标签到指定commitgit 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
8、解决冲突
更新本地代码git pull查看状态git status手动修改删除冲突内容重新提交git add 、 git commit
9、参考教程
廖雪峰Git教程 Gitee教程
10、示例代码
[rootecs-xxx ~]# git
-bash: git: command not found
[rootecs-xxx ~]#
[rootecs-xxx ~]# sudo apt-get install git
sudo: apt-get: command not found
[rootecs-xxx ~]#
[rootecs-xxx ~]# yum install git
Loaded plugins: fastestmirror
Complete!
[rootecs-xxx ~]# git version
git version 1.8.3.1
[rootecs-xxx ~]# whereis git
git: /usr/bin/git /usr/share/man/man1/git.1.gz
[rootecs-xxx ~]# pwd
/root
[rootecs-xxx /]# cd home
[rootecs-xxx home]# mkdir learngit
[rootecs-xxx home]# cd learngit
[rootecs-xxx learngit]# pwd
/home/learngit
[rootecs-xxx learngit]# git init
Initialized empty Git repository in /home/learngit/.git/
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# ls -a
. .. .git
[rootecs-xxx learngit]# touch readme.txt
[rootecs-xxx learngit]# ls
readme.txt
[rootecs-xxx learngit]# vim readme.txt
[rootecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
[rootecs-xxx learngit]# git add readme.txt
[rootecs-xxx learngit]# git commit -m wrote a readme file.*** Please tell me who you are.Rungit config --global user.email youexample.comgit config --global user.name Your Nameto set your accounts default identity.
Omit --global to set the identity only in this repository.fatal: unable to auto-detect email address (got rootecs-xxx.(none))
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git config --global user.email xxxxxxemail.com
[rootecs-xxx learngit]# git config --global user.name xxxxxx
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git config --list
user.emailxxxxxxemail.com
user.namexxxxx
core.repositoryformatversion0
core.filemodetrue
core.barefalse
core.logallrefupdatestrue
remote.origin.urlgitgitee.com:xxxxx/learngit.git
remote.origin.fetchrefs/heads/*:refs/remotes/origin/*
branch.master.remoteorigin
branch.master.mergerefs/heads/master
[rootecs-xxx learngit]#
[rootecs-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
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
[rootecs-xxx learngit]# vim readme.txt
[rootecs-xxx learngit]#
[rootecs-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)
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git diff
diff --git a/readme.txt b/readme.txt
index 1a0762b..68fe139 100644
--- a/readme.txtb/readme.txt-1,2 1,3 Git is a version control system.xf
Git is free software.
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git add readme.txt
[rootecs-xxx learngit]# git status
# On branch master
# Changes to be committed:
# (use git reset HEAD file... to unstage)
#
# modified: readme.txt
#
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git commit -m add new line
[master 910aa81] add new line1 file changed, 1 insertion()
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
[rootecs-xxx learngit]#
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# vim readme.txt
[rootecs-xxx learngit]# git add readme.txt
[rootecs-xxx learngit]# git commit -m add system time
[master 331832a] add system time1 file changed, 1 insertion()
[rootecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git log
commit af264a5ada2e059ad822d7121fa2e595129198de
Author: xxxxxx xxxxxxemail.com
Date: Thu Mar 2 10:01:05 2023 0800:
Date: Thu Mar 2 10:06:21 2023 0800add system timecommit 910aa81c9bade65244b9ba43a74f225dc931f22e
Author: xxxxxx xxxxxxemail.com
Date: Thu Mar 2 10:03:55 2023 0800add new linecommit af264a5ada2e059ad822d7121fa2e595129198de
Author: xxxxxx xxxxxxemail.com
Date: Thu Mar 2 10:01:05 2023 0800wrote a readme file.
[1] Stopped git log
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git log --prettyoneline
331832aa56734d0f34517fd246ceb32b32ed20a2 add system time
910aa81c9bade65244b9ba43a74f225dc931f22e add new line
af264a5ada2e059ad822d7121fa2e595129198de wrote a readme file.
[rootecs-xxx learngit]#
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git reset --hard HEAD^
HEAD is now at 910aa81 add new line
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# cat readme.txt
Git is a version control system.
xf
Git is free software.
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git log
commit 910aa81c9bade65244b9ba43a74f225dc931f22e
Author: xxxxxx xxxxxxemail.com
Date: Thu Mar 2 10:03:55 2023 0800add new linecommit af264a5ada2e059ad822d7121fa2e595129198de
Author: xxxxxx xxxxxxemail.com
Date: Thu Mar 2 10:01:05 2023 0800wrote a readme file.
[rootecs-xxx learngit]# [rootecs-xxx learngit]# touch license.txt
[rootecs-xxx learngit]# vim license.txt
[rootecs-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)
[rootecs-xxx learngit]# vim readme.txt
[rootecs-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.
[rootecs-xxx learngit]#
[rootecs-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)
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git add readme.txt
[rootecs-xxx learngit]# git add license.txt
[rootecs-xxx learngit]# git status
# On branch master
# Changes to be committed:
# (use git reset HEAD file... to unstage)
#
# new file: license.txt
# modified: readme.txt
#
[rootecs-xxx learngit]# git commit -m add new file license.txt
[master 40b3936] add new file license.txt2 files changed, 2 insertions()create mode 100644 license.txt
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
[rootecs-xxx learngit]#
[rootecs-xxx learngit]#
[rootecs-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.
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# vi readme.txt
[rootecs-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.
[rootecs-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)
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git checkout -- readme.txt
[rootecs-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.
[rootecs-xxx learngit]#
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# vi readme.txt
[rootecs-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!!
[rootecs-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)
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git add readme.txt
[rootecs-xxx learngit]# git status
# On branch master
# Changes to be committed:
# (use git reset HEAD file... to unstage)
#
# modified: readme.txt
#
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git reset HEAD readme.txt
Unstaged changes after reset:
M readme.txt
[rootecs-xxx learngit]#
[rootecs-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!!
[rootecs-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)
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git checkout -- readme.txt
[rootecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
[rootecs-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.
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# touch test.txt
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git status
# On branch master
# Untracked files:
# (use git add file... to include in what will be committed)
#
# test.txt
nothing added to commit but untracked files present (use git add to track)
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git add test.txt
[rootecs-xxx learngit]# git commit -m add test.txt
[master cd18992] add test.txt1 file changed, 0 insertions(), 0 deletions(-)create mode 100644 test.txt
[rootecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# rm test.txt
rm: remove regular empty file ‘test.txt’? y
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# ls
license.txt readme.txt
[rootecs-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)
[rootecs-xxx learngit]# git checkout -- test.txt
[rootecs-xxx learngit]# ls
license.txt readme.txt test.txt
[rootecs-xxx learngit]#
[rootecs-fjx learngit]#
[rootecs-fjx 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.
[rootecs-fjx learngit]# [rootecs-xxx ~]# ssh-keygen -t rsa -C xxxxxxemail.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 emailemail.com
The keys randomart image is:
---[RSA 2048]--------[SHA256]-----
[rootecs-xxx ~]#
[rootecs-xxx ~]# ls -a
. .bash_history .bash_profile .cshrc .history .pki .tcshrc
.. .bash_logout .bashrc .gitconfig mirrors_source.sh .ssh .viminfo
[rootecs-xxx ~]# cd .ssh
[rootecs-xxx .ssh]# ls
authorized_keys id_rsa id_rsa.pub
[rootecs-xxx .ssh]# cat id_rsa.pub
[rootecs-xxx learngit]# git remote add origin gitgitee.com:xxxxx/learngit.git
[rootecs-xxx learngit]# git remote -v
origin gitgitee.com:xxxxx/learngit.git (fetch)
origin gitgitee.com:xxxxx/learngit.git (push)
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git status
# On branch master
nothing to commit, working directory clean
[rootecs-xxx learngit]# [rootecs-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 detailsgit pull remote branchIf you wish to set tracking information for this branch you can do so with:git branch --set-upstream-toorigin/branch master[rootecs-xxx learngit]#
[rootecs-xxx learngit]# ls
license.txt readme.txt test.txt
[rootecs-xxx learngit]#
[rootecs-xxx learngit]#
[rootecs-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 gitgitee.com:xxxxx/learngit.git! [rejected] master - master (non-fast-forward)
error: failed to push some refs to gitgitee.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.
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# git pull --reabse origin master
error: unknown option reabse
usage: git fetch [options] [repository [refspec...]]or: git fetch [options] groupor: git fetch --multiple [options] [(repository | group)...]or: git fetch --all [options]-v, --verbose be more verbose-q, --quiet be more quiet--all fetch from all remotes-a, --append append to .git/FETCH_HEAD instead of overwriting--upload-pack path path to upload pack on remote end-f, --force force overwrite of local branch-m, --multiple fetch from multiple remotes-t, --tags fetch all tags and associated objects-n do not fetch all tags (--no-tags)-p, --prune prune remote-tracking branches no longer on remote--recurse-submodules[on-demand]control recursive fetching of submodules--dry-run dry run-k, --keep keep downloaded pack-u, --update-head-ok allow updating of HEAD ref--progress force progress reporting--depth depth deepen history of shallow clone--unshallow convert to a complete repository[rootecs-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
[rootecs-xxx learngit]#
[rootecs-xxx learngit]# ls
license.txt README.en.md README.md readme.txt test.txt
[rootecs-xxx learngit]#
[rootecs-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 gitgitee.com:xxxxx/learngit.git58bbad5..6aca85e master - master
Branch master set up to track remote branch master from origin.
[rootecs-xxx learngit]#