..." to include in what will be committed) 2 3nothing added to commit but untracked fi_切换 up to date ">
当前位置:   article > 正文

Git常用撤销命令_切换 up to date with main

切换 up to date with main

1. add操作后,需要撤销

(base) ➜  git-study git:(main)git add -A
(base) ➜  git-study git:(main)git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   2
	new file:   3
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

此时使用 git reset HEAD命令即可

(base) ➜  git-study git:(main)git reset HEAD
(base) ➜  git-study git:(main)git status
On branch main
Your branch is up to date with 'origin/main'.

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

nothing added to commit but untracked files present (use "git add" to track)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2. add + commit操作后,需要撤销

(base) ➜  git-study git:(main)git add -A
(base) ➜  git-study git:(main)git commit -m "123"
[main 02db97b] 123
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 2
 create mode 100644 3
(base) ➜  git-study git:(main) git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

此时使用 git reset HEAD^ 即可

(base) ➜  git-study git:(main) git reset HEAD^
(base) ➜  git-study git:(main)git status
On branch main
Your branch is up to date with 'origin/main'.

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

nothing added to commit but untracked files present (use "git add" to track)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

3. push过程中,因为误添加大文件push失败

通常报错为

remote: error: File hadoop-2.7.7.tar.gz is 208.59 MB;
this exceeds GitHub's file size limit of 100.00 MB
  • 1
  • 2
(base) ➜  git-study git:(main)git status
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	2
	3
	hadoop-2.7.7.tar.gz

nothing added to commit but untracked files present (use "git add" to track)
(base) ➜  git-study git:(main)git add -A
(base) ➜  git-study git:(main)git commit -m "add all"
[main b9879ce] add all
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 2
 create mode 100644 3
 create mode 100755 hadoop-2.7.7.tar.gz
(base) ➜  git-study git:(main) git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 208.49 MiB | 960.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 2509943b599314908891e273b18e6dee23fa9fab6e5396aec3bb60e97c502a31
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File hadoop-2.7.7.tar.gz is 208.59 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/lyyang233/git-study.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/***.git'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

此时候使用 git rm --cached hadoop-2.7.7.tar.gz
并使用git commit --amend -m “delete large file” 重置commit
最后push即可

(base) ➜  git-study git:(main) git rm --cached hadoop-2.7.7.tar.gz
rm 'hadoop-2.7.7.tar.gz'
(base) ➜  git-study git:(main)git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	deleted:    hadoop-2.7.7.tar.gz

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	hadoop-2.7.7.tar.gz
(base) ➜  git-study git:(main)git commit --amend -m "delete large file"
[main 3a3cb9b] delete large file
 Date: Fri Dec 25 18:31:42 2020 +0800
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 2
 create mode 100644 3
(base) ➜  git-study git:(main)git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

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

nothing added to commit but untracked files present (use "git add" to track)
(base) ➜  git-study git:(main)git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 289 bytes | 289.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To https://github.com/***.git
   3eb7530..3a3cb9b  main -> main
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/734852
推荐阅读
相关标签
  

闽ICP备14008679号