Git Push --Force will destroy the timeline and kill us all - Computer Stuff They Didn't Teach You #7

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024

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

  • @J4M350N
    @J4M350N 3 ปีที่แล้ว +4

    "Please try to avoid doing a force push to your _main_ branch"
    Totally agree! However, I would like to add that in (feature) branches where you're the only one working on force pushing can be very helpful to keep a clean history. For example, if one of the commits broke the build (or unit tests or whatever) then I'd just remove/fix that commit with a force push. It also helps to always have a working build if you ever use git-bisect :)
    Love these vids!

  • @manolovalenzuela
    @manolovalenzuela 4 ปีที่แล้ว +25

    Gracias Scott!!! It's an honor :)

  • @buriedstpatrick2294
    @buriedstpatrick2294 4 ปีที่แล้ว +8

    It should probably be mentioned that force-pushing is very useful and completely normal when working on your own feature-branches (that others don't push to). Rewriting history is fine when rebasing your feature-branch on the main-branch before submitting a PR for instance. I know we're only talking a single branch here for simplicity, but I think it's important to mention that force-push isn't just a last-ditch-effort tool.

    • @shanselman
      @shanselman  4 ปีที่แล้ว +3

      Great point!

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

      With lease. --force-with-lease, always, never --force.

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

      @@BertrandLeRoy Yep, he should do a follow up video explaining WHEN to use force and how to do it properly

  • @sarcasmasaservice
    @sarcasmasaservice 4 ปีที่แล้ว +18

    Hey Scott, more great stuff, again, thanks! And let me say that I enjoy the no edit style you've adopted. It makes what's happening easier to follow and add a certain humanistic feeling to your tutorials that just isn't found in other, highly edited videos. Keep up the great work!

  • @char3tek
    @char3tek 4 ปีที่แล้ว +17

    @5:00 S.H.’s voice saying “Thank you, friend. We want you to be quiet now.” Is the creepiest thing I have ever heard outside of a horror movie.

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

      👁

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

      You usually only hear that line if you're about to swim with the fish.

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

    Scott kudos for this series! They are valuable and help developers to be more effective. These concepts and their implementation should be prerequisite in any coding focused training course.

  • @crysise94
    @crysise94 4 ปีที่แล้ว +3

    I must say this is amazing and please do continue to do this way of teaching. I wonder who all were lucky to work with someone like you :)

  • @simonwales7317
    @simonwales7317 4 ปีที่แล้ว +20

    "... or a really bad sequel" - hilarious as ever Mr H.

  • @RonyBatistaInoa
    @RonyBatistaInoa 4 ปีที่แล้ว +11

    Love your vids man. The console and wsl series helped convince me to come back to windows after 8 years on OS X.

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

    I have been working with git for a while but there's always something to learn and sure enough, your videos gave me more understanding. Thanks!

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

    As requested - liked that, subscribed and shared with friends :) Keep up with a great work!

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

    Very grateful for all the stuff you teach us Scott! Wonderful series. I'm always looking forward to a new episode. Thanks a lot!

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

    I love your channel, Mr. Hanselman. The depth of your knowledge and your calm delivery are worth coming back for. Content for clear minds 😌

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

    These are great videos. I know Git has been around for a while - but it's very complex and uses its own terminology and thus I think these are timeless.

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

    Scott, really enjoying this series - looking forward to what is next. I'm not sure if it is in your road map for this or not - but I would love to see a video on best practices around common git workflows. I work on an ops team and we are getting into git for our PowerShell work. Again, thanks for the content.

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

    Wonderful session, Scott, Thank you very much.

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

    Make it intermittently rain with those dozens of TH-cam dollars! But in all honestly I have learnt so much .Net from your blogs and now from your videos

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

    I like Scott. Very good learning resource. I've referred this vid to our junior devs (and some of our senior ones LOL).

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

    Your videos have been a great help!
    A request -- Please make a video on how to generate SSH keypair, authenticate public key, and adding SSH keypair to ssh-agent using Powershell.
    Also, if possible, a video covering 'git push --force-with-lease' with its different parameters/options would be a big help as well.

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

    Can you talk about some basic networking stuff like localhost and ports? I’ve never really understood it but trying to use WSL2 and learn a bit of web dev so it’s been coming up more often.

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

    Great to know you're becoming rich with this great series of videos !!!

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

    I burst out laughing when you were trying to paste that thing, I just think you're very funny. (been following you since 2015)

  • @nilesh-gule
    @nilesh-gule 4 ปีที่แล้ว

    Love the ambience of your room. Feels so divine. 👍

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

    As a concrete example of "what" changes during a history rewrite, pause at time-index 12:56 and note that from the third commit message in the log (left side of the screen) downwards, the commit SHA1 matches the corresponding commit's SHA1 on GitHub (right side of the screen). However, the top two "rebased/rewritten" commits in the log now have different SHA1 values because the parent commit of "Update test - Copy.txt (23c5163)" changed to the commit "Merge pull request #6 (d4fa5c9)" from the previous parent commit of "Merge pull request#5 (3a3664a)" i.e., the commit that was removed. Since a commit's SHA1 value incorporates the commit's parent SHA1 value, changing the parent of a commit makes that commit and subsequent commits in the timeline appear as all-new commits.

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

      To add to this, the SHA1 depends on the entire history (comments, authors, parents, content) of a commit. So even changing one letter in one file during a rebase will change the SHA1 of all subsequent commits. That's why force breaks things for people who are still referencing the old commit.

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

    Dev: git push --force
    Computer: are you sure you know what you are doing? If yes, type: I'm about to screw things up and press enter

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

      One of my favorite things I learned from my job was how to update a hard drive's firmware or an SSD's firmware through the command 'hdparm'. The following below is the exact syntax to use to tell hdparm to try to update the drive's firmware:
      hdparm /dev/sda --yes-i-know-what-i-am-doing --please-destroy-my-drive --fwdownload mybinary.bin
      It literally makes you type out in verbose language: --yes-i-know-what-i-am-doing --please-destroy-my-drive
      I thought my boss was joking with me and a coworker when he gave us that command. No way could those seriously be the arguments to use! He's warning us to be careful!
      Those are the real arguments.

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

    Great video again. I had a good laugh when Alexa interrupted

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

    Hi Scott, first of all, amazing your explanation makes it easy to understand anything, thanks so much for that.
    I have a doubt, usually, when you do a rebase-interactive (-i) you got a prompt with some text information about the commits, etc... I saw you got that prompt in the VS Code, my Windows Terminal prompt me to "VI editor" :( How can I configure my Windows Terminal to prompt me to the VS Code ??
    Thanks in advance.
    Cheers!

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

      That's the core.editor config item! stackoverflow.com/questions/2596805/how-do-i-make-git-use-the-editor-of-my-choice-for-commits

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

    Greyishbeard hanselman approaching final form.

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

    Don’t think we didn’t catch the caveat at the end where you said “avoid doing this to MAIN” (paraphrase).

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

    Great video, Scott. If I cloned your repo before git push -force, what should I do to update my local repo? git pull? Also, is there a way to fix the "4 commits behind, 1 commit ahead" issue in github or is it just a warning message? Please explain more not recommended git practices (and how to deal with them) in future videos. Thanks!

  • @johlits
    @johlits 4 ปีที่แล้ว +3

    Just tell him change his password

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

    hypothetically, what would happen subsequently after a dev re-wrote history by doing a git push force? How could an individual fix this, back to the point where every one can all have the same history again?.. you should do a segment on that

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

    If I had cloned your repo before you removed the password (ie when ede923b was the newest commit), would I need to do something special to get back in sync, or should I just be able to pull again?

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

      If you run a git fetch you'll see that you'd be "desynced" like he showed. To get back to the "real" main branch, you'd have to reset it.
      I usually use: git reset --hard /
      So for instance, on branch named master with remote named origin:
      git reset --hard origin/master
      Beware that this will orphan your local commits not on the remote like he explained. It's like a force pull if that makes sense.

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

    This is nice to have vlog

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

    Thanks a lot sir, no wonder ppl really really really hate something with "-force", so in this example, the only way to get around with a posted password is to make in invalid on the backend.
    I think similar situation applies to mistakenly added unwanted files to .gitignore ? So no way to undo it once it is pushed !?

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

    If this happens in the feature branch before making a pull request still is a bad idea?

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

      As long as you are the only person referencing that branch, you're fine. Once it is 'published' (to github for example), it's a Very Bad Idea. Unless you know for sure that no-one else is referencing it. Or you don't care.

  • @ImranAli04
    @ImranAli04 4 ปีที่แล้ว +3

    Flash point

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

    Can you do a video on how to backup your entire repository ? I saw option on bundles and achieve commands but is that the best way or just zip up the directory .

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

    "...and kill us all" 😄. Made my day

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

    What color theme, extensions etc do you use with VS, VS Code ?

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

      That theme is called Yonce

  • @buildervision7082
    @buildervision7082 11 หลายเดือนก่อน

    Thank you so much, now i know better!

  • @23d1nis
    @23d1nis 4 ปีที่แล้ว

    Would you do this if someone deleted everything in the repo? 🤔

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

    Is your themed powershell as a result of WSL? is it possible without using WSL? I tried setting it up unsuccessfully with WSL.

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

      He is using the new Windows Terminal with Powershell, no WSL required :) Windows Terminal can be found in the Microsoft app store. It's HIGHLY customisable. He also mentioned in this video that he is using Pretty Prompt to display additional information about the directory location.

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

      google "hanselman pretty prompt"

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

    Scott . Can You please put playlist link on Description please!

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

    Showing force at all without mentioning - - force-with-lease is problematic. A good follow-up could be to show how to do it right, which is in your own branch, with lease, to get a clean commit history. In this case it's not only fine to force (with lease) push, it's what makes rebase really useful (and harmless).

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

      I did mention force-with-lease.

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

      Do you want to send another PR and let's do another, ok?

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

      @@shanselman Sorry I missed it. Glad you mentioned it. I'd love to send you a PR, but isn't the scenario here that the person doing the rewrite would be the one making the PR? I mean, as you said in the video, the secret scenario is a little contrived, as that secret is compromised now and the right mitigation is to change the secret. I think the justified scenario for --force-with-lease is the following (at least it's the one I'm doing on almost every PR I do, I know you know how to do all that, just spelling it out for accuracy): publish a PR, get some code review, make some changes, some of which make the commit history as it is hard to follow because some things are done, undone, and re-done differently. To give future readers a clear view of what the change really is about, a cleaned up commit history is useful. So you do an interactive rebase (the most common way I do it is to have a new correction commit that I fixup into the existing one, when it's a single commit PR, or a more complex interactive rebase in more advanced scenarios), then push force with lease because there's no other way to get the fixes in without doing a new PR. As an aside, VS online is currently a little better than GitHub at showing PR history & diffs in such scenarios, hope GH catches up on that.
      I think that would be a nice follow-up that would also be an opportunity to talk about other cool git practices around good PRs and code reviews.

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

    If you add your AWS keys on accident you’ll know when you get the insane bill from people spinning up Bitcoin mining machines in your aws account, haha. This actually happened to multiple people while I was in university

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

    But if you put in another PR with the password removed, wouldn't the password still be viewable in the git history? You would have to do a git push --force to prevent this wouldn't you?
    Also, I cloned another repo because it had the folder structure I wanted them completely developed a new project in it. Now the git history for this project shows the full history from the previous project, even though there are no longer any files in my project related to the original repo. How can I remove (squash?) all the history prior to a specific point?

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

      Use interactive rebase to drop the old commits or start a new branch and cherry-pick the new ones over.

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

      If you only want to adopt the cloned repos folder structure first clone the repo, the create a new folder for your project and copy the folder structure to the new folder and git init a new repo there. I don't think it is a good idea to reuse an existing repo as the starting point for a new project.

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

      @@grumpydeveloper69 Thanks Thomas and Johan. I already have this setup in a private repo, and wouldn't mind keeping all my commits for the last two months.
      If I use an interactive rebase now and drop any old commits, will the code in those commits still exist?

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

      @@st3ddyman You could do it. See this stackoverflow that explain different option including the rebase option as shown in @Scott Hanselman video. stackoverflow.com/questions/37471740/how-to-copy-commits-from-one-git-repo-to-another

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

    Great video!!! :))

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

    MAKE ROOM TOUR VIDEO

  • @hemanthkotagiri8865
    @hemanthkotagiri8865 4 ปีที่แล้ว +3

    I think you should also include learning Vim in this series. It's going to be really helpful for many of us.

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

      Well, assuming that you know how to vim considering the massive years of experience you've got. But, hey, great videos, Scott! Love'em!

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

    In school (1990 - 1995) Git was not invented :)

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

      That explains why it wasn't taught! ;)

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

    Who is here after Spiderman no way home meme?

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

    Start Videos on ML...