Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น • 271

  • @coreyms
    @coreyms  6 ปีที่แล้ว +188

    I made a slight mistake in the video. The -f option on git clean is for "force" and not for "files". The documentation can be found here for more info:
    git-scm.com/docs/git-clean

    • @hamidadesokan6528
      @hamidadesokan6528 5 ปีที่แล้ว +11

      You are a God send to humanity. Thank you :)

    • @KL-es9bt
      @KL-es9bt 5 ปีที่แล้ว +6

      Explanation Very Clear.!! Please videos on Merge and Rebase. Thank you so much! I learn a lot from the videso.

    • @Eaglea12k
      @Eaglea12k 3 ปีที่แล้ว

      thought it while watching, but got answer while came to make some comments on your video

    • @PimpMyYugioh
      @PimpMyYugioh ปีที่แล้ว

      Did you have to use -d or could you have taken it out

  • @ajeethv
    @ajeethv 4 ปีที่แล้ว +236

    1:42 - Revert back the code that was written
    3:36 - Updating the commit message alone (amend)
    5:50 - Accidentally left off a file that we wanted to commit
    7:38 - Move the commits to a different branch (cherry-pick)
    10:26 - 3 different types of reset
    13:38 - Getting rid of untracked files (git clean)
    15:01 - Retrieve critical files that were lost, and you want them back (git reflog)
    18:10 - Backing out changes, when other people have already checked out your changes (git revert)

    • @pacedelacruz4913
      @pacedelacruz4913 4 ปีที่แล้ว

      Ajeeth Kumar Thanks for this Ajeeth👍👍

    • @willdoyoutube
      @willdoyoutube 4 ปีที่แล้ว

      Thanks!

    • @moeinmhzg7827
      @moeinmhzg7827 3 ปีที่แล้ว

      Thanks dude. You saved my time🙏🏻

    • @YanasChanell
      @YanasChanell 3 ปีที่แล้ว

      thanks!

    • @AnthaaBaagundaali
      @AnthaaBaagundaali 3 ปีที่แล้ว

      Thanks a lot. Your comments helped clearly understand what Corey was trying to say.

  • @janarthananv3268
    @janarthananv3268 6 ปีที่แล้ว +40

    Am DevOps. Best tutorial for python and git so far. Even paid tutorials are not able to reach this level of profession . Keep it up :)

  • @pooyarowgh
    @pooyarowgh 4 ปีที่แล้ว +10

    I am git newbie. This video saved my files that I thought I lost in a series of unintended commits. About 2 weeks worth of work! Thanks so much Corey and keep up the good work.

  • @avishal4
    @avishal4 9 ปีที่แล้ว +148

    One of the best git (or any other) tech videos i've seen in a long long time! Great job!!

    • @klue16
      @klue16 7 ปีที่แล้ว +3

      This.

    • @someonlinevideos
      @someonlinevideos 5 ปีที่แล้ว +1

      Absolutely. No bullshit ego stuff up front or at end. Just right to the point with clear simple examples and explanations. Bravo

  • @carlellis9647
    @carlellis9647 6 ปีที่แล้ว +27

    This is the second video I've watch by Corey. I've been in software development for over 20 years and he explains Git better than anybody I've come across. Keep up the great work you're doing. :)

  • @studyonline3236
    @studyonline3236 5 ปีที่แล้ว +11

    I can see simplicity and at the same time your professional way of explaining it. Thank you for investing your time to save our's

  • @aleksagordic9593
    @aleksagordic9593 6 ปีที่แล้ว +1

    Perfect video, thanks! Keep it going, guys like you make this world a better place.
    1 advice though: use head/head~/head~n/head^ syntax instead of sha-1 codes so that you can focus more on the intention and less on the implementation details of git.
    For example:
    10:40 - instead of using git log to find sha-1 codes, just use git reset --soft head~
    (I want to reset to the second to latest commit)
    20:00 - instead of using git log to find sha-1 codes, just use git diff head~ head
    (i.e. I want a diff between second to latest commit and latest commit on the branch I'm on)
    additional tips:
    - checkout head^ which differs from head~ only when you have merge commits. (you can also use head^n)
    - use head~n to go back n commits into the past.
    - head is a synonym for the sha-1 of the latest commit.

  • @BanglawalaNeesarg
    @BanglawalaNeesarg 5 ปีที่แล้ว +5

    After deciding to ditch the Git GUI in favor of command-line, I came across your videos. You have done a fantastic job compiling the essentials and demoing them! It feels like I finally understand what ACTUALLY is going on when I use these commands. Thank you!!

  • @timfitzgerald1923
    @timfitzgerald1923 8 ปีที่แล้ว +37

    Brilliant structure and sequencing and crystal clear examples. A lot of key functionality covered effectively and concisely.

  • @sriramab
    @sriramab 6 ปีที่แล้ว +1

    Wow. Watched all the videos on GIT. The flow and structure of the lecture(s) in all the videos is so smooth, that I Never had to rewind and ponder .." what did he say"... . More than perfect !

  • @bensonjunior833
    @bensonjunior833 ปีที่แล้ว +2

    Best git tutorial out there

  • @archtaurus
    @archtaurus 7 ปีที่แล้ว +22

    The most awesome tutorial about git reset/checkout/revert commands, I ever seen so far. Great! Thankyou!

    • @coreyms
      @coreyms  7 ปีที่แล้ว +1

      Thanks!

    • @BantuTu
      @BantuTu 5 ปีที่แล้ว +1

      Came here to say this.

  • @deoray
    @deoray 6 ปีที่แล้ว +7

    Very very helpful tutorial for some of the more advance/obscure features related to rollback and reset. While this tutorial is long and someone in need of quick answer may run out of patience, I still recommend a good listen. Its better to know details rather than following commands without knowing basics. Thanks Corey for quality tutorial.

  • @jadia
    @jadia 4 ปีที่แล้ว +1

    The BEST video on advanced git out there. I'm amazed by the use cases Corey has shown. I can't thank you enough for the efforts you put. I'll definitely do my part to support your channel.

  • @JamesLee-Im-All-In
    @JamesLee-Im-All-In 3 ปีที่แล้ว +1

    Best git tutorial ever made on planet earth.

  • @PaulMcCannWebBuilder
    @PaulMcCannWebBuilder 6 ปีที่แล้ว

    Despite the quick 'clears', which throw off and freak out beginners, this is the clearest explanation of fixing mistakes and changing history. Thanks.

  • @MauricioSalazare
    @MauricioSalazare 2 ปีที่แล้ว

    This is the best video tutorial for Git. Neat, straight to the point, stunningly clear. High quality teaching.

  • @ashishm8413
    @ashishm8413 6 ปีที่แล้ว +6

    After watching this video, I wish I could give it a thumbs-up 51 times so you hit 1000. Deserves it!

  • @ubaidraza1165
    @ubaidraza1165 4 ปีที่แล้ว +2

    You are awesome. your teaching skills are extraordinary In 21 minutes you just cleared everything that I need to understand to get rid of all those confusions that often happened to me.
    Thank you so much

  • @kunalk1896
    @kunalk1896 2 ปีที่แล้ว

    This is one of the best videos for someone who manages git repository. Loved it

  • @chrisk8703
    @chrisk8703 7 ปีที่แล้ว

    I've never learned something about version control before but the way how you teach programming stuff is just amazing. While watching the first two videos about git I was myself asking questions like "ok but what if I accidently write a wrong comment" but you go through all those traps and show the appropriate solutions. Thanks for sharing your knowledge!

  • @FAAAx2
    @FAAAx2 2 ปีที่แล้ว

    I paid 30€ for a git course of multiple hours. Well, I just discovered this video and it's quite better for 0€. Thank you

  • @balam856
    @balam856 7 ปีที่แล้ว +2

    Presenter has good knowledge on the topic & great presentation skills.... That's what makes this video great !!! Thanks for sharing your knowledge....

  • @amanthakur1987
    @amanthakur1987 6 ปีที่แล้ว +2

    Exactly what a developer needs rather than bombing with extra useless stuff on git. Good one.....Thanks...

  • @vaclavhanzl8193
    @vaclavhanzl8193 6 หลายเดือนก่อน

    I gotta be honest. I am new to all of this and I was a liitle bit intimidated by Git commands but damn... These videos are perfect. Thank you very very much!

  • @harshwardhanrathore8973
    @harshwardhanrathore8973 8 ปีที่แล้ว +10

    One of the most helpful video on git that I came across, great job :)

  • @antonyspiano2403
    @antonyspiano2403 3 ปีที่แล้ว

    Not commenting anything special, cause Only God knows how this tutorial helped me . Thanks a ton brother !

  • @jonathanbrand3379
    @jonathanbrand3379 6 ปีที่แล้ว

    Thank you so much for this tutorial. A lot of guides and videos focus on the 'happy' path of using git in development, but tend to leave aside the ugly bits that creep into our workflow more often than we'd expect.

  • @jasarora9331
    @jasarora9331 4 ปีที่แล้ว +1

    This is a must watch for every junior dev (including me).

  • @amardeepbhowmick3614
    @amardeepbhowmick3614 6 ปีที่แล้ว +3

    Best video on git ever!! intuitive and covers most of the practical use cases!

  • @laureen69
    @laureen69 5 ปีที่แล้ว +2

    That's what 'advance' git tutorial i've been looking for... superb thank you

  • @PrashantYadav-xw7do
    @PrashantYadav-xw7do 4 ปีที่แล้ว

    I love the way you teach. It's very easy to understand and apply everything, I do recommend your lectures to everyone cause you are super cool. Thanks man

  • @dhanashree318
    @dhanashree318 7 ปีที่แล้ว +5

    Thanks a ton for your efforts in making this. All your videos are amazingly well explained in simplistic way.

  • @dhairyalakhera893
    @dhairyalakhera893 3 ปีที่แล้ว

    Complete undoing in just 21 minutes...
    Great video...

  • @fendevfendev5903
    @fendevfendev5903 5 ปีที่แล้ว +3

    One of the best git videos I have seen. Thank you Corey!

  • @masihsadri
    @masihsadri 6 ปีที่แล้ว +1

    very good tutorial
    as a suggestion: if you use "git log --oneline --graph --all" is better than "git log" for new users.
    you can also define new alias at first and use it instead of "git log":
    how to create an alias command:
    alias ThisOne="git log --oneline --graph --all" is better than "git log"
    --
    and now you can you "ThisOne" instead of "git log"
    Best Regards

  • @jasminaoukde2016
    @jasminaoukde2016 5 ปีที่แล้ว +2

    Lots of useful information in one place, I really enjoyed it :) Thanx Corey

  • @rishigupta2507
    @rishigupta2507 6 ปีที่แล้ว +1

    Best git videos I have ever seen great job bro!!

  • @shubhamaggarwal4800
    @shubhamaggarwal4800 7 ปีที่แล้ว +16

    this guy deserve a medal for this :)

  • @JohnnyMetz
    @JohnnyMetz 7 ปีที่แล้ว +5

    Best git video I've ever seen by far. Well done!

  • @pratyushsingh1606
    @pratyushsingh1606 3 ปีที่แล้ว

    You are amazing.. I have seen tons of videos.. But after watching this, i was like.. This is how you explain.. Thank you for taking out time to make this amazing video 😍

  • @TReXcuRRy
    @TReXcuRRy 4 ปีที่แล้ว +1

    Great video. Clear and densely packed info, with excellent examples. Thank you.

  • @ArshilGenius
    @ArshilGenius 5 ปีที่แล้ว +3

    Cleared lot of doubts! Thanks!

  • @mtahiralauddin
    @mtahiralauddin 2 ปีที่แล้ว

    On 2:13 you didn't write a bunch of gibberish. You wrote exactly the same line 4 times except for the line number 4.
    You exactly wrote sdfasdfasdf 4 times. Your talent

  • @dabeanman808
    @dabeanman808 4 ปีที่แล้ว

    Dude!!! Thank you so much for these git walkthroughs, best on youtube IMO!

  • @avinavsingh5157
    @avinavsingh5157 5 ปีที่แล้ว

    improper use of git has cost a lot of people their jobs, do you know what a great video you have made....cheers man.Thank You.

  • @tambolaking5383
    @tambolaking5383 4 ปีที่แล้ว +1

    Awesome tut. With examples it made damn easy to understand

  • @amrelsayed4363
    @amrelsayed4363 6 ปีที่แล้ว

    Perfect Git Tutorial, BTW while studying the tutorial, trying "git reflog" i accidently typed reset commit id instead of checkout and then the backup branch hasle and guess what it gave me the same thing!
    Thanks a lot really great tutorial

  • @On7D7
    @On7D7 3 ปีที่แล้ว +1

    Cory you are life sever !!! I was crying ...

  • @mathewkargarzadeh3158
    @mathewkargarzadeh3158 6 ปีที่แล้ว +1

    I loved the lessons. getting more in depth knowledge on git.
    Thanks Corey !!!. you are the best

  • @Jack-dx7qb
    @Jack-dx7qb 2 ปีที่แล้ว

    Thank you for the high-quality tutorial. I have learned so much from you! Best wishes.

  • @goutamkundu6392
    @goutamkundu6392 4 ปีที่แล้ว +1

    Great tutorial on git. I highly appreciate your efforts. Many thanks

  • @chaiti19
    @chaiti19 5 ปีที่แล้ว +8

    Best of the best!!Thank you is an understatement!!

  • @howards5205
    @howards5205 4 ปีที่แล้ว

    Wow, these videos are SUPER helpful. I'm going to watch it again.

  • @saurabhmittal6947
    @saurabhmittal6947 4 ปีที่แล้ว +1

    This is really some very very important content. Thank you. You just got one more subscriber :)

  • @vinodboddukuri
    @vinodboddukuri 4 ปีที่แล้ว

    Nicely covered all git mistakes that people generally do. Thank you very much for making this video.

  • @apoorv9492
    @apoorv9492 2 ปีที่แล้ว

    Really good straight forward tutorials. Highly appreciated Corey.👍

  • @SiphoMkhwanazi
    @SiphoMkhwanazi 6 ปีที่แล้ว +2

    @Corey Schafer thank you for this tutorial. You're a life saver.

  • @hichamsouleimani1920
    @hichamsouleimani1920 4 ปีที่แล้ว

    I learned a lot from your second video on git. Thank you again.

  • @3mar1997
    @3mar1997 3 ปีที่แล้ว

    You are an absolute legend and a True teacher ❤️🔥

  • @greggompers16
    @greggompers16 2 ปีที่แล้ว

    Corey's videos are the best
    Thank you Corey

  • @amineurin944
    @amineurin944 7 ปีที่แล้ว +6

    Just amazing Corey. Thanks!
    reflog FTW!

  • @iorbit
    @iorbit 6 ปีที่แล้ว +1

    You explain everything very clearly and in a good pace

  • @padmavatijadhav4173
    @padmavatijadhav4173 7 ปีที่แล้ว +3

    thanks a lot . it was really helpful video which Cleared most of our doubts. and probably will save hassle in future.

  • @keshavparad4792
    @keshavparad4792 3 ปีที่แล้ว

    Thank you man u saved my project
    love from india

  • @danielb.6476
    @danielb.6476 5 ปีที่แล้ว +1

    No more gitkraken for cherry-picking! 🕺🏿 Awesome video! Thanks for this.

  • @PimpMyYugioh
    @PimpMyYugioh ปีที่แล้ว

    Such a well-explained video. Really helpful! Even for someone who has read most of the Pro Git book

  •  7 ปีที่แล้ว +2

    Wow!!! This is perfect! Excellent explanation. Thank you

  • @sunilpoojari91
    @sunilpoojari91 4 ปีที่แล้ว +1

    Very Informative Video!
    Thank You So Much. 🙌🏻

  • @codewithsub5083
    @codewithsub5083 5 ปีที่แล้ว +2

    Really a great video. Learnt a lot from this video.
    Thanks

  • @1apocalyps
    @1apocalyps 7 ปีที่แล้ว

    Great video straight to the point and not a second was wasted!!

  • @TheSumanb
    @TheSumanb 3 ปีที่แล้ว

    One of the best , please keep on publishing great thanks , subscribed :)

  • @rajeshantony74
    @rajeshantony74 7 ปีที่แล้ว +7

    one of the Excellent video on git..thank you so much

  • @josemadrid4343
    @josemadrid4343 4 ปีที่แล้ว

    Awesome video. You explain things in a way that just make sense. Thank you.

  • @urbanmunda2451
    @urbanmunda2451 3 ปีที่แล้ว

    Amazing video. cleared all my doubts. Thanks a lot

  • @seancharles1595
    @seancharles1595 5 ปีที่แล้ว +2

    Outstandingly useful, Thank you.

  • @aram5642
    @aram5642 4 ปีที่แล้ว

    Great vid! When it comes to git reset there is also a "keep" option but I have never had a clear situation to see its benefits.

  • @alexisaddicted
    @alexisaddicted 4 ปีที่แล้ว +1

    Amazing, user-friendly explanation!!!!

  • @greatgibson0
    @greatgibson0 7 ปีที่แล้ว

    I bet this video saved many lives.

  • @ladislavszabo4247
    @ladislavszabo4247 4 ปีที่แล้ว +1

    great explanation, thanks for video!

  • @madhavgd4365
    @madhavgd4365 4 ปีที่แล้ว

    Awesom tutorial i ever seen about git reset/reset /reset hard/revert commands

  • @girish2555
    @girish2555 2 ปีที่แล้ว

    Crystal clear explanation 🔥

  • @vinaykhurana9933
    @vinaykhurana9933 6 ปีที่แล้ว +1

    What a wonderful explanation!!! Superb job. :)

  • @bozhang525
    @bozhang525 5 ปีที่แล้ว

    For reset --hard, you don't need to use checkout and then create a backup to restore. YOu can simply use reset --hard . Say A->B->C, after doing git reset --hard B, you can do git reset --hard C to go back to C. The only issue with --hard is that all uncommitted changes will be lost.

  • @CuriousAnand
    @CuriousAnand 4 ปีที่แล้ว +1

    Seriously, this is a life saver!

  • @jkmutea
    @jkmutea 3 ปีที่แล้ว

    Best git video I have seen .. keep it up

  • @pacedelacruz4913
    @pacedelacruz4913 4 ปีที่แล้ว +1

    Awesome video. Thanks again.

  • @mahitejgangaraju2842
    @mahitejgangaraju2842 6 ปีที่แล้ว +1

    Great Video. covers all the important scenarios

  • @sebastianbraun2473
    @sebastianbraun2473 6 ปีที่แล้ว +1

    Best explanation by far

  • @cuongngo7858
    @cuongngo7858 6 ปีที่แล้ว

    @Corey Schafer I have a question , around 3:00 , after we add some code on master branch, when I execute git checkout otherbranch, those changes on master branch are also move to otherbranch, it differs from what I see from the video, what did I miss?

  • @ivanovmg
    @ivanovmg 6 ปีที่แล้ว +1

    This lesson is awesome! Thank you for very clear explanation!

  • @mithunpolawar749
    @mithunpolawar749 4 ปีที่แล้ว +1

    Awesome explanation..!

  • @KamelJabber1
    @KamelJabber1 5 ปีที่แล้ว +1

    Fantastic video!

  • @enriquemillanvalbuena5241
    @enriquemillanvalbuena5241 4 ปีที่แล้ว +1

    Thank you so much for your video. It is really handy! :D

  • @parthokr
    @parthokr 3 ปีที่แล้ว

    Just wow! Great tutorial on git undoing

  • @mogreen1249
    @mogreen1249 7 ปีที่แล้ว

    Excellent critical video really good ,just subscribed ,Thanks Corey Schafer.

  • @ashrafulfuad2967
    @ashrafulfuad2967 5 ปีที่แล้ว +1

    Thank you so much this is really helpful for git learners

  • @kumarprateek1279
    @kumarprateek1279 5 ปีที่แล้ว

    Great playlist for beginners.Just need couple of more videos on resolving merge conflicts etc

  • @fabianwinkelmann3931
    @fabianwinkelmann3931 4 ปีที่แล้ว

    To get an overview over the complete git history type "git log --all --decorate --oneline --all". You can also assign an alias, so you don't have to write the previous command out everytime. alias graph="git log -all --decorate --oneline --all". Then you can just type graph