Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits

Поделиться
HTML-код
  • Опубликовано: 21 авг 2024
  • In this video we will look at some common mistakes in Git and how we can fix these mistakes. Specifically we will cover how to discard changes since your last commit, amending commits, cherry-picking hashes, resetting to a specific commit, and reverting to a specific commit.
    ✅ Support My Channel Through Patreon:
    / coreyms
    ✅ Become a Channel Member:
    / @coreyms
    ✅ One-Time Contribution Through PayPal:
    goo.gl/649HFY
    ✅ Cryptocurrency Donations:
    Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
    Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
    Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
    ✅ Corey's Public Amazon Wishlist
    a.co/inIyro1
    ✅ Equipment I Use and Books I Recommend:
    www.amazon.com...
    ▶️ You Can Find Me On:
    My Website - coreyms.com/
    My Second Channel - / coreymschafer
    Facebook - / coreymschafer
    Twitter - / coreymschafer
    Instagram - / coreymschafer
    #Git

Комментарии • 270

  • @coreyms
    @coreyms  6 лет назад +187

    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 4 года назад +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 года назад +235

    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!

    • @basivijunna627
      @basivijunna627 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 3 года назад +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 8 лет назад +149

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

    • @klue5903
      @klue5903 7 лет назад +3

      This.

    • @someonlinevideos
      @someonlinevideos 4 года назад +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 5 лет назад +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 4 года назад +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

  • @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 7 лет назад +37

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

  • @archtaurus
    @archtaurus 6 лет назад +22

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

    • @coreyms
      @coreyms  6 лет назад +1

      Thanks!

    • @BantuTu
      @BantuTu 4 года назад +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.

  • @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 !

  • @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

  • @aleksagordic9593
    @aleksagordic9593 5 лет назад +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.

  • @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!

  • @PaulMcCannWebBuilder
    @PaulMcCannWebBuilder 5 лет назад

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

  • @JamesLee-tg9xl
    @JamesLee-tg9xl 2 года назад +1

    Best git tutorial ever made on planet earth.

  • @jadia
    @jadia 3 года назад +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.

  • @amanthakur1987
    @amanthakur1987 6 лет назад +2

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

  • @MauricioSalazare
    @MauricioSalazare 2 года назад

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

  • @vaclavhanzl8193
    @vaclavhanzl8193 Месяц назад

    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!

  • @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!

  • @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

  • @tahiralauddin79
    @tahiralauddin79 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

  • @jasarora9331
    @jasarora9331 3 года назад +1

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

  • @shubhamaggarwal4800
    @shubhamaggarwal4800 7 лет назад +16

    this guy deserve a medal for this :)

  • @harshwardhanrathore8973
    @harshwardhanrathore8973 8 лет назад +10

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

  • @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.

  • @masihsadri
    @masihsadri 5 лет назад +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

  • @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....

  • @antonyspiano2403
    @antonyspiano2403 3 года назад

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

  • @dhanashree318
    @dhanashree318 7 лет назад +5

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

  • @laureen69
    @laureen69 5 лет назад +2

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

  • @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.

  • @dhairyalakhera893
    @dhairyalakhera893 3 года назад

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

  • @JohnnyMetz
    @JohnnyMetz 6 лет назад +5

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

  • @bensonjunior833
    @bensonjunior833 Год назад +2

    Best git tutorial out there

  • @fendevfendev5903
    @fendevfendev5903 5 лет назад +3

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

  • @amardeepbhowmick3614
    @amardeepbhowmick3614 6 лет назад +3

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

  • @ArshilGenius
    @ArshilGenius 4 года назад +3

    Cleared lot of doubts! Thanks!

  • @On7D7
    @On7D7 3 года назад +1

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

  • @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

  • @jasminaoukde2016
    @jasminaoukde2016 4 года назад +2

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

  • @avinavsingh5157
    @avinavsingh5157 4 года назад

    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.

  • @rishigupta2507
    @rishigupta2507 6 лет назад +1

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

  • @chaiti19
    @chaiti19 5 лет назад +8

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

  • @danielb.6476
    @danielb.6476 5 лет назад +1

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

  • @pratyushsingh1606
    @pratyushsingh1606 2 года назад

    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 😍

  • @amineurin944
    @amineurin944 7 лет назад +6

    Just amazing Corey. Thanks!
    reflog FTW!

  • @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

  • @TReXcuRRy
    @TReXcuRRy 3 года назад +1

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

  • @iorbit
    @iorbit 6 лет назад +1

    You explain everything very clearly and in a good pace

  • @mathewkargarzadeh3158
    @mathewkargarzadeh3158 6 лет назад +1

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

  • @tambolaking5383
    @tambolaking5383 4 года назад +1

    Awesome tut. With examples it made damn easy to understand

  • @dabeanman808
    @dabeanman808 4 года назад

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

  • @3mar1997
    @3mar1997 2 года назад

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

  • @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.

  •  6 лет назад +2

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

  • @SiphoMkhwanazi
    @SiphoMkhwanazi 5 лет назад +2

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

  • @keshavparad4792
    @keshavparad4792 2 года назад

    Thank you man u saved my project
    love from india

  • @greggompers16
    @greggompers16 Год назад

    Corey's videos are the best
    Thank you Corey

  • @apoorv9492
    @apoorv9492 Год назад

    Really good straight forward tutorials. Highly appreciated Corey.👍

  • @rajeshantony74
    @rajeshantony74 7 лет назад +7

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

  • @goutamkundu6392
    @goutamkundu6392 4 года назад +1

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

  • @vinodboddukuri
    @vinodboddukuri 4 года назад

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

  • @seancharles1595
    @seancharles1595 4 года назад +2

    Outstandingly useful, Thank you.

  • @codewithsub5083
    @codewithsub5083 5 лет назад +2

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

  • @hichamsouleimani1920
    @hichamsouleimani1920 3 года назад

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

  • @Jack-dx7qb
    @Jack-dx7qb 2 года назад

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

  • @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

  • @saurabhmittal6947
    @saurabhmittal6947 4 года назад +1

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

  • @PimpMyYugioh
    @PimpMyYugioh Год назад

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

  • @sunilpoojari91
    @sunilpoojari91 4 года назад +1

    Very Informative Video!
    Thank You So Much. 🙌🏻

  • @howards5205
    @howards5205 3 года назад

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

  • @maqdala
    @maqdala 3 года назад

    Now I seriously understood what git reset does.

  • @girish2555
    @girish2555 2 года назад

    Crystal clear explanation 🔥

  • @urbanmunda2451
    @urbanmunda2451 2 года назад

    Amazing video. cleared all my doubts. Thanks a lot

  • @slaklad4321
    @slaklad4321 7 лет назад +28

    Perfect Lesson

  • @1apocalyps
    @1apocalyps 6 лет назад

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

  • @greatgibson0
    @greatgibson0 6 лет назад

    I bet this video saved many lives.

  • @XxNGameCubexX
    @XxNGameCubexX 5 лет назад

    "We want to get back to the way things were..."
    Haha you said that so many times that I just started laughing after a while.
    Great set of videos, by the way! Thanks for teaching me how to use git!

  • @josemadrid4343
    @josemadrid4343 3 года назад

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

  • @ladislavszabo4247
    @ladislavszabo4247 4 года назад +1

    great explanation, thanks for video!

  • @TheSumanb
    @TheSumanb 2 года назад

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

  • @ivanovmg
    @ivanovmg 6 лет назад +1

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

  • @sebastianbraun2473
    @sebastianbraun2473 5 лет назад +1

    Best explanation by far

  • @CuriousAnand
    @CuriousAnand 4 года назад +1

    Seriously, this is a life saver!

  • @alexisaddicted
    @alexisaddicted 4 года назад +1

    Amazing, user-friendly explanation!!!!

  • @pacedelacruz4913
    @pacedelacruz4913 4 года назад +1

    Awesome video. Thanks again.

  • @madhavgd4365
    @madhavgd4365 4 года назад

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

  • @srikanthshetty6150
    @srikanthshetty6150 7 лет назад +13

    excellent video

  • @vinaykhurana9933
    @vinaykhurana9933 5 лет назад +1

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

  • @mahitejgangaraju2842
    @mahitejgangaraju2842 5 лет назад +1

    Great Video. covers all the important scenarios

  • @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.

  • @BrechtGijbels
    @BrechtGijbels 7 лет назад +2

    Very clear! Thank you 👍

  • @mithunpolawar749
    @mithunpolawar749 4 года назад +1

    Awesome explanation..!

  • @jkmutea
    @jkmutea 3 года назад

    Best git video I have seen .. keep it up

  • @KamelJabber1
    @KamelJabber1 5 лет назад +1

    Fantastic video!

  • @parthokr
    @parthokr 3 года назад

    Just wow! Great tutorial on git undoing