Giter Site home page Giter Site logo

git-sockcamp's Introduction

Jeff's Git Sockcamp

Experiments and lessons-learned with git.

1. git push "un-do"

Problem statement: Ugh! My colleague just told me that a push I did a couple of weeks ago had junk in it that doesn't belong in our repo. I need to pull back that push without disturbing the rest of our repo.

The Plan: Use git revert

To exercise this scenario, I'll create three text files and push them to the remote repository.

After the third git push, I'll "un-do" that second push.

% echo "# git-sockcamp" >> About.md
% echo "# kill-sockcamp" >> KillThis.md
% echo "# Sockcamp Outline" >> Outline.md
% git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	About.md
	KillThis.md
	Outline.md

KillThis.md is our "bad" file; we'll want to back out that push.

% git add About.md
% git commit -m "About.md initial commit"
[main 00817ee] About.md initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 About.md
% git push origin main 
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 10 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 296 bytes | 296.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/GumptionWare/git-sockcamp.git
   472cea6..00817ee  main -> main
% 
% git add KillThis.md
% git commit -m 'Add KillThis.md'
[main bd356db] Add KillThis.md
 1 file changed, 1 insertion(+)
 create mode 100644 KillThis.md
% git push origin main 
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 10 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 330 bytes | 330.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/GumptionWare/git-sockcamp.git
   00817ee..bd356db  main -> main
# I also set remote to origin/main   
branch 'main' set up to track 'origin/main'.
%
% git add Outline.md
% git add README.md
% git commit -m 'Ouline.md (new): README updates'
[main d14a90e] Ouline.md (new): README updates
 2 files changed, 20 insertions(+)
 create mode 100644 Outline.md
 % git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 10 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 909 bytes | 909.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/GumptionWare/git-sockcamp.git
   bd356db..d14a90e  main -> main
%

Git Revert

% # OK, now let's "un-do" the bad push:
% # SHA of KillSockcamp.md commit: bd356db3cec27ad7dd236b507724ccbda0134228
% git revert bd356db3cec27ad7dd236b507724ccbda0134228
[main d6f86e5] Revert "Add KillThis.md"
 1 file changed, 1 deletion(-)
 delete mode 100644 KillThis.md
% 
% #After completing the prompt for the commit message:
% 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 push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 10 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 275 bytes | 275.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/GumptionWare/git-sockcamp.git
   8fbe711..d6f86e5  main -> main

Success!! Looking in GitHub, I see the "KillThis.md" file is gone. (Imagine a nice screenshot here.)

Use git ls-files to confirm the local repo contents

% git ls-files
About.md
Outline.md
README.md

Our "KillThis.md" file is gone. Kewl, eh?

git-sockcamp's People

Contributors

gumptionware avatar

Watchers

 avatar drew avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.