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
此时使用 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)
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
此时使用 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)
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
(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'
此时候使用 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