git分布式版本控制系统的本地备份,提交远程仓库以及其他操作
git的本地备份,远程备份相关代码本地备份远程备份相关代码git init初始化仓库git status查看状态git add添加追加git add --allgit commit -m “xxx” 提交git log查看历史版本git log -p 查看历史提交详细git file.txt 查看历史版本-2 最近两个历史版本git reset --hard/soft+版本号回滚(–hard回滚历
相关代码
git init 初始化仓库
git status查看状态
git add 添加追加 git add --all
git commit -m “xxx” 提交
git log 查看历史版本 git log -p 查看历史提交详细
git file.txt 查看历史版本 -2 最近两个历史版本
git reset --hard/soft +版本号 回滚
(–hard回滚历史版本,文件内容也会回滚
–soft回滚历史版本,文件内容不会回滚)
git reflog 查看每次操作的版本号
git remote -v 查看远程仓库别名设置
git remote add origin +远程仓库地址 (添加别名映射)
git remote remove origin 删除映射别名
git push origin master 推
git pull origin master 拉
git pull origin master --allow-UNrelated-histories 强制拉取,合并
本地备份
1.初始化一个仓库在D盘下面的文件夹
git init
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git init
Reinitialized existing Git repository in D:/git/.git/
2.此时会多出一个.git仓库
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ ls -al
total 45
drwxr-xr-x 1 admin 197609 0 Jan 3 17:30 ./
drwxr-xr-x 1 admin 197609 0 Jan 3 15:05 ../
drwxr-xr-x 1 admin 197609 0 Jan 4 00:05 .git/
-rw-r--r-- 1 admin 197609 2179 Jan 3 17:30 .gitignore
drwxr-xr-x 1 admin 197609 0 Jan 3 15:30 bbbb/`在这里插入代码片`
-rw-r--r-- 1 admin 197609 12524 Dec 19 23:48 ddddd.txt
-rw-r--r-- 1 admin 197609 14 Jan 3 16:25 file.txt
3.试着将这个.git删除
rm -rf .git
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ rm -rf .git
4.查看提交状态
git status
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git status
On branch master
No commits yet(#还未提交)
Untracked files:(#没有被追踪的文件)
(use "git add <file>..." to include in what will be committed)
.gitignore
ddddd.txt
file.txt
nothing added to commit but untracked files present (use "git add" to track)
5.提交(追踪)一个文件(file.txt)到本地备份,并且再次查看状态
git file.txt
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git add file.txt
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: file.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
ddddd.txt
(#可以看到file.txt已经被提交到历史版本)
6.将所有追踪的文件进行提交
git commit -m (“进行说明”)
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git commit -m(进行一个说明) "add file.txt"
[master (root-commit) a638f5f] add file.txt
1 file changed, 4 insertions(+)
create mode 100644 file.txt
7.查看历史提交记录
git log
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git log
commit a638f5fe5757128f0e96e26fd77cdf3ab3a1fb48 (HEAD -> master)
Author: tgzzwjz <1123644258@qq.com>
Date: Tue Jan 4 00:24:26 2022 +0800
add file.txt#所提交的文件
8.查看历史提交详细
git log -p
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git log -p
commit a638f5fe5757128f0e96e26fd77cdf3ab3a1fb48 (HEAD -> master)
Author: tgzzwjz <1123644258@qq.com>
Date: Tue Jan 4 00:24:26 2022 +0800
add file.txt
diff --git a/file.txt b/file.txt
new file mode 100644
index 0000000..2d3385e
--- /dev/null
+++ b/file.txt
@@ -0,0 +1,4 @@
+dds#提交的内容
+ddsf
+dsf
+
9.将所有的文件进行提交
git -al
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git add --all
10.回滚(回到)历史版本
git reset --hard commit a638f5fe5757128f0e96e26fd77cdf3ab3a1fb48
#commit后面为历史版本号,知道版本号可以回到任意版本
–hard回滚历史版本,文件内容也会回滚
–soft回滚历史版本,文件内容不会回滚
默认为soft
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git reset --hard a638f5fe5757128f0e96e26fd77cdf3ab3a1fb48
HEAD is now at a638f5f add file.txt
11.查看历史版本号
从上往下是最新的版本号
git reflog
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git reflog
a638f5f (HEAD -> master) HEAD@{0}: reset: moving to a638f5fe5757128f0e96e26fd77cdf3ab3a1fb48
ac5a950 HEAD@{1}: commit: add c.txt
a638f5f (HEAD -> master) HEAD@{2}: commit (initial): add file.txt
远程备份
1.在gitte中新建一个仓库
在语言和添加 .gitignore选项中都选择为python
2.点击,gitignore
在最后一行加上.idea/表示在该文件夹下的修改暂时无效
3.查看远程仓库别名设置
git remote -v
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git remote -v
4.添加别名映射(仓库地址)
origin为别名(可以自己改)
git remote add origin https://gitee.com/tgzzwjz/bbb
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git remote add origin https://gitee.com/tgzzwjz/bbb
5.进行push与pull操作
并且输入gitte用户名及密码
git push origin master
git pull origin master
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git push origin master
To https://gitee.com/tgzzwjz/bbb
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/tgzzwjz/bbb'
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.
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git pull origin master
From https://gitee.com/tgzzwjz/bbb
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
6.强制进行pull与push操作
并且传输成功的表现
git pull origin master --allow-unrelated-histories
admin@LAPTOP-N4C2QNI5 MINGW64 /d/git (master)
$ git pull origin master --allow-unrelated-histories
From https://gitee.com/tgzzwjz/bbb
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
.gitignore | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 139 insertions(+)
create mode 100644 .gitignore
更多推荐
所有评论(0)