How to exclude commits from git?

Aleksey Timoshchenko

Yesterday in git history appeared commits that should not be there.

Here is an screenshot

enter image description here

It happened because of it was needed to clean files that were under .gitignore but still were tracked by git. In order to do it we used this answer on SO

https://stackoverflow.com/a/23839198/5709159

And all is works like it should. But we realized that actually not all the files that were under .gitignore (mistake) should be deleted...

Issue is - that for now these commits were pushed and we need to exclude them (revert)

Are there some ideas how to do it?

Is there a way to take all these files that were deleted (we can see them in commit) and include it again in new commit?

P.S. Files were in git, but then they were deleted and pushed to git. Now we need to get them back.

For example we have such commit history A - B - C - D. We have some important files in commit A then in commit B these files were deleted, then in commit C - D we make regular commits with logic implementation and so on. So, files that were deleted in commit B we need to get back. We need to exclude commit B and leave commits C - D. Something like this A - C - D. Or another way is A - B - C - D - B.

jo_

of course you can revert

git revert <SHA of erroneous commit>

or, you can rewrite the complete history BUT this will update all SHA which can be dangerous (if someone else is allready working on the branch)

for this you would have to freeze the others developpers to work during this

git checkout branchA   // one of the problematic branch
git rebase -i <sha1 befor the pb>
-->   mark the "remove ignored file" commit as `edit`
// this will stop into the "guilty commit"
// at this point we undo the commit 
git reset HEAD^ 
// and then redo do the job like it should have 
....
// including the  "git commit "
// you can even do more than one git "commit"
git rebase --continue

// then 
git push -f origin branchA

Other dev can now pull again

Note : to do it more safely you can create a work branch and drop it if result is not as expected

git checkout branchA   // one of the problematic branch
git checkout -b branchA-before-rework // just in case

git checkout -b A-rework-1
git revert <SHA1 erroneous commit>

// ? happy :)
git branch -f branchA   // will force branchA to here
git push -f origin branchA
// not happy try something else

git checkout branchA   // one of the problematic branch
git checkout -b A-rework-2
// do above "git rebase -i" stuff EXCEPT push -f
// ? not happy drop it
git checkout branchA   // one of the problematic branch
git checkout -b A-rework-n
// ? happy :)
git branch -f branchA   // will force branchA to here
git push -f origin branchA

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to exclude from commits but not delete?

How to exclude unnecessary commits from a pull request?

Is it possible to exclude the commit message from git commits from SHA Algorithm?

How to view a linear `git log` (exclude feature commits), showing only commits to `main` or merges to `main`

How to remove a tag from newer commits in git?

How to remove specific commits from Git?

How git maintains commits from deleted branch?

How to examine Git commits from another branch?

How to remove commits from GIT origin?

In git, how to create a branch with commits from branch A, minus commits from B, plus commits from C?

how to exclude typescript compiled files from git

How to exclude a specific git submodule from update?

Git exclude certain commits and the code change and keep the other commits on top

How to exclude new git branches that don't any commits while finding the branches that has been merged to current?

git - from a local branch how to pull down commits from master

How to pack commits in git

How to copy commits from one Git repo to another?

How to remove trailing whitespace changes from a sequence of git commits

How to print / log all git commits messages from certain commit?

How to sign git commits from within an IDE like IntelliJ?

How to delete commits from gitlab? (Git-revert not working)

How to avoid merge commits from Git pull when pushing to remote

How to remove duplicated commits from filter-branch command on git?

In Git, how can I reorder (changes from) pushed commits?

git:how to push commits to the existing pull request from another person?

How to completely remove unwanted branches and commits from Git repo

GIT how to split up commits from branch into different branches?

How to read git commits from hard disk in my software?

Git: how to import commits from another repository and unsquash them?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive