This is the first day of my participation in the Gwen Challenge in November. Check out the details: the last Gwen Challenge in 2021

Git rebase: Git rebase: Git rebase: Git rebase: Git rebase: Git rebase

ERROR:

Enumerating objects: 204, done. Counting objects: 100% (204/204), done. Delta compression using up to 8 threads Compressing objects: 100% (158/158), done. error: RPC failed; Curl 55 Send failure: the Connection was aborted fatal: the remote end hung up unexpectedly | 11.00 KiB/s Writing objects: 100% (172/172) and 28.02 MiB | 178.00 KiB/s, done. Total 172 (102) delta, reused zero (0) delta, pack – reused zero fatal: the remote end hung up unexpectedly Everything up-to-date

According to the record of some solutions found in the process of solving the problem:

Large files cannot be pushed to remote repositories

  • Commit large files cannot be pushed to the remote repository solution
  • Git filter-branch

Rollback after git commit

  • Git reset –hard discards the latest commit
  • Git rebase -i discards the specified commit

git rebase

  • Exit after git rebase execution failed
  • Rollback after git rebase succeeds

There is no specific solution to this problem (delete a file in the commit history and then push it again), but it was a mistake at the beginning and was handled with ***git rebase and git reset

The problem

First of all, the origin of the story (accident) is this.

A git push to a remote repository failed to commit a large file (the large file is a PDF file)

$ git push Enumerating objects: 204, done. Counting objects: 100% (204/204), done. Delta compression using up to 4 threads Compressing objects: 100% (183/183), done. Writing objects: 100% (187/187) and 419.00 MiB | 2.21 MiB/s, done. Total 187 (21) delta, reused zero (0) delta remote: Resolving deltas. 100% (21/21), completed with 12 Local objects. Remote: Powered by GITEE.COM [gnK-3.8] remote: error: File: Db501995ac30070d50bdc115a7708f9ba84332d3 403.57 MB, exceeds 100.00 MB. Remote: Use the command below to see the filename: remote: git rev-list --objects --all | grep db501995ac30070d50bdc115a7708f9ba84332d3 remote: Please remove the file from history and try again. (https://gitee.com/help/articles/4232) To gitee.com:findmoon/xxxx.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to '[email protected]:findmoon/xxxx.git'Copy the code

Follow the prompts to see which big file is

Commit large files cannot be pushed to the remote repository solution

First, the solution is to modify the commit history and delete the commit record of large files that have been committed to the local repository.

Git filter-branch –tree-filter ‘rm -f file name ‘HEAD to delete a specified file from the commit history

Delete the large files as follows

$ git filter-branch --tree-filter 'rm -f "Electron/pdf/677969 xxxx xxx.pdf"' HEAD
Rewrite d1244f8fbc1f08b473bd498c023b09bd8ac3246b (12/12) (156 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten
Copy the code

A successful deletion returns the Ref ‘refs/ Heads/Master ‘was rewritten prompt, or unchanged if returned.

If the file path contains Spaces, use quotation marks to enclose the deleted file path.

Then push again successfully.

The overall operation is as follows:

git filter-branchCommand:

Rollback after git commit

There are two ways to undo a COMMIT that has already been committed:

  • usegit reset --hard HEAD^
  • usegit rebase -i HEAD~n

Git reset –hard discards the latest commit

After the code is submitted, the requirements have changed so that the previously submitted code is no longer suitable, or the code has been submitted after a serious bug, need to roll back, but use this command:

git reset --hard HEAD^

1, HEAD^ denotes the position of the latest committed HEAD.

2, HEAD~n indicates the number of back submissions of the latest HEAD position

The reset command can only roll back the latest commit. If you only want to delete one of the specified commits, but keep the last one or two commits, reset cannot do this.

The reset git command deletes a specific commit

Git rebase -i discards the specified commit

If you want to undo an intermediate commit, use the following command:

Git rebase -i HEAD~2(list the last two commits and decide what to do with them)

  1. rebase -iisrebase --interactiveThe abbreviation of;
  2. git rebase -iYou can not only delete the COMMIT, but also modify it. You can check the detailsrebaseIn

Run git rebase to check the command parameters:

$git rebase -i HEAD~2 pick 71add05 20200225 Pick 45d4805 commit # rebase 36b460a.. 45d4805 onto 36b460a (2 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. # # Note that empty commits are commented outCopy the code

Common ones are as follows:

  • Edit: With this commit, rebase is paused until the commit is made
  • Pick: Use this submission
  • Drop: Deletes the commit

View the last three commits and drop (DROP) the penultimate commit. Save and exit to delete all the contents committed in the penultimate commit

Roll back the latest commit: both the git reset and git rebase commands work

Rollback a commit: Git rebase is ok, git reset is not

If the commit has been synchronized to the remote repository, use git push Origin -f branch to synchronize the rollback to the remote repository as well (use -f with caution for the master branch).

git rebase

git rebaseExit after an execution failure

Like the one above, the implementation of the git rebase may result in failure, embodied in bash logo into the warehouse (master | rebase 1/10) (m/n depending on reabse edit content)

Git rebase –abort to the current branch with data and files recovered.

git rebaseA successful rollback

Git rebase: Git rebase: git rebase: git rebase: Git rebase: Git rebase: Git rebase: Git rebase

Do not delete a commit with git rebase -I HEAD

Git rebase -i HEAD~2: git rebase -i HEAD~2: git rebase -i HEAD~2: git rebase -i HEAD~2: git rebase -i HEAD~2: git rebase -i HEAD~2 Nor can it be retained (to the state of all files and folders at the time of the latest submission)

You can use git reset –hard ID to directly restore the commit to the specified commit time.

  • git reflogView Git commit records

As shown above, you can directly see what commit ID you want to restore to. For example, run the git reset –hard 71add05 command to restore to the time when the Id is 71add05. The local repository and files can be restored to the specified commit time.

Succeeded in resuming a specified COMMIT. Procedure

After deleting the file, run git add -a or git rm

to add the deletion to the staging area. No, the difference is as follows:

  • git add -ASave all changes (including deleted files, new files, and changes to existing files)
  • git add .Save new additions and changes, but not deletions
  • git add -uSaves changes and deletions, but does not include new files.