Ausnahme gefangen: SSL certificate problem: certificate is not yet valid ๐Ÿ“Œ How to Undo the Most Recent Local Commits in Git?

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š How to Undo the Most Recent Local Commits in Git?


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

In this article this is what we are going to learn

  1. Immediate Undo with git reset
  • How to use the git reset command? How does it work?

  • Step by Step code example for undoing the most recent commit, using git reset HEAD~

  • Discussing the use of ย --soft, --mixed and --hard flags

2. Reverting changes with git revert

  • What is git revert and when to use git revert instead of git reset

  • Code example explaining how to revert a specific commit without altering project history

3. Using git reflog to navigate and restore commit history

  • git reflog a tool for viewing all past commits, even the ones removed from branch history

  • code example to demonstrate how to use git reflog with git reset to revert to a specific point in history

4. Bonus-managing-merge-conflicts-after-reverting-commits

  • Overview of merge conflicts

  • Strategies for resolving conflicts effciently with code examples

5. Bonus: Best Practices for Commit Management

  • Using clear and descriptive titles

  • Using branches effectively for feature development and testing

  • git cherry-pick command and its uses

Immediate undo with git reset

You can immediately undo changes with the git reset command. With git reset you can revert the project to previous state without altering the files ( depending on the options selected). In this section we are going to learn how to effectively use the git reset command

git reset changes the current state of a branch to a specified commit thus effectively undoing the subsequent commits

here are the primary flags that you can use with git reset

  • --soft:

  • --mixed (default)

  • --hard

These flags are explained in detail in the below coding example

each of these flags does a different level of undo, affecting commit history and the state of files in the working directory

Coding example with git reset

  1. Open the terminal and navigate to the project root directory

  2. to undo the most recent commit type the below command

git reset HEAD~

What are we doing here?

We are using the HEAD~ which means we want to revert to the commit just before the current HEAD.

We are also not signifying any options for the git reset command and thus it will default to mixed which means it will revert any changes but not affect any files in the working directory

here is an example with the --hard option

git reset --hard HEAD~

3. You can verify the changes by checking the status like so

git status

You can see the changes from the undone commit in the staging area

Explaining different flag options namely --soft, --mixed and --hard.

  • --soft: This will undo your commits but leave your changes staged. You can use the --soft option to modify commit messages or combine them with another commit

  • --mixed (default): This undo the commit and unstages the changes, but leaves them in your working directory. This is a safe option because it does not risk losing any changes.

  • --hard: the undoes the commit, unstages the changes and discards all the changes and the files in the working directory, since the commit. This could lead to loss of work when not used properly

Revert Changes with git revert

git revert creates a new commit that undo the changes that were made by the previous commit (one or more previous commit).

Contract it with git reset which basically erases the commit (one or more previous commits) from the commit history

This approach ensures that project history remains intact and traceable, thus it is a good method for undoing the changes when working in a shared repo with code that has already been shared with other people

  • Git revert is Non Destructive: It does not erases the commit, creates a new commit that undo the changes by one or more previous commits

  • Teams and collaborative environments: When working in teams you might want to not erase tehe faulty comit from history

When to use git revert and when to use git reset

  • Shared History: Use the Git revert when you want to undo the changes that have been pushed to a public repository. This is because the git reset deletes the history which might cause confusion and might create conflicting histories. Using git revert keeps the history consistant for all contributers

  • Preserving History: If we are maintaining a detailed record for all the changes that are occuring the repository then you want to use the git revert command. The git revert command allows you to see what was undone and why it was undone by the developer.

Code example using git revert

Let us consider an example of git revert. Here we have a commit with hash jdfhg4535289 that we want to revert

  1. open the terminal and go to the working directory of your project

  2. use the git revert like

git revert jdfhg4535289

This command creates a new commit that will undo the changes of the jdfhg4535289 commit.

The new commit will create a default commit message that will indicate which commit is being reverted but you can customize the message as well as you see fit

Git might automatically open your code editor as well in order to let you specify any commit message you might want to

3. Resolve any conflicts that might arise

  • If the changes introduced by the commit jdfhg4535289 conflict with changes in subsequent commit (the commit that will be there once you undo this commit) you will be asked by Git to resolve these conflicts manually

  • After you have resolved the conflicts you will be asked to finalize the revert by completing the revert process. This might involve adding the resolved files to the staging area using git add and then completing the commit using git commit

4. Verify the operation using git log

You can verify the operation that has been completed using the git log command. You can see a new commit that revert the changes of the jdfhg4535289 commit in the

Using git reflog to navigate and restore commit history

git reflog gives a record of the git branches and other references in your repository. This includes commits, resets, merges and rebases

This includes actions that might alter your visible history, thus making git reflog useful for recovering lost commits or viewing the project's state at a specific instance in time

Contract this with git log which just shows your commit history of your current branch

Detailed explanation of git reflog

  • Git reflog tracks the tips of the branches and git references within your local repository

  • the reflog in git reflog means reference log

  • Each entry in reflog is a reference to a specific point in time thus the reflog provides a chronological list of changes in the repository.

  • These changes might include branch commit history, resets or rebases and thus it offers a way to restore lost commits

Code Example for git reflog

In this example we are going to ue git reflog along with git reset to restore a commit.

let us consider a situation where you accidentally reset the current branch to an older commit thus losing several important commits in the process

We can use the git reflog. to find these lost commits and restore the code to its previous state

  1. Open the terminal and navigate to the working directory

  2. type the git reflog command to view the recent changes in your repo

git reflog

The commit will give you a list of commits with HEAD, the commit hash and a description of the action (That is commit, reset or merge).

3. Select the entry corresponding to the state that you want to restore

  • Each entry in the git reflog shows a snapshot of a specific action. Look for the commit or action that is just before the accidental reset.

4. Restore your branch to the desired state using git reset

git reset --hard HEAD@{the entry from the git reflog};

This command will reset your current branch to the previous branch at the specific point in time.

git reset --hard HEAD@{0}



Metered TURN servers

Metered TURN servers

  1. Global Geo-Location targeting: Automatically directs traffic to the nearest servers, for lowest possible latency and highest quality performance. less than 50 ms latency anywhere around the world

  2. Servers in 12 Regions of the world: Toronto, Miami, San Francisco, Amsterdam, London, Frankfurt, Bangalore, Singapore,Sydney, Seoul

  3. Low Latency: less than 50 ms latency, anywhere across the world.

  4. Cost-Effective: pay-as-you-go pricing with bandwidth and volume discounts available.

  5. Easy Administration: Get usage logs, emails when accounts reach threshold limits, billing records and email and phone support.

  6. Standards Compliant: Conforms to RFCs 5389, 5769, 5780, 5766, 6062, 6156, 5245, 5768, 6336, 6544, 5928 over UDP, TCP, TLS, and DTLS.

  7. Multiโ€‘Tenancy: Create multiple credentials and separate the usage by customer, or different apps. Get Usage logs, billing records and threshold alerts.

  8. Enterprise Reliability: 99.999% Uptime with SLA.

  9. Enterprise Scale: With no limit on concurrent traffic or total traffic. Metered TURN Servers provide Enterprise Scalability

  10. 50 GB/mo Free: Get 50 GB every month free TURN server usage with the Free Plan

  11. Runs on port 80 and 443

  12. Support TURNS + SSL to allow connections through deep packet inspection firewalls.

  13. Support STUN

  14. Supports both TCP and UDP

Bonus: Managing merge conflicts after reverting commits

Merge conflicts happen when two branches that have conflicting code are merged together

This can happen in different scenarios including when you revert the changes in one branch

A revert modifies the files to a previous state and if we try to merge this branch with another that has moved forward, a conflict might arise if same parts of the file were edited

Merge conflicts arise when GIT cannot automatically resolve differences in code between two commits.

Thus these commits need to be manually resolved before merging can be completed.

Ways to resolve conflicts

  1. Understanding the conflict: understand why the conflict is occuring, you can use the git status command to see which files have a conflict.

  2. Deciding on the correct changes: See the conflict and decide which changes you want to keep and which one you want to discard

  3. Using Git tools and editors: Instead of using the git status you can use various git tools, even vscode has conflict resolution tool built in that you can use.

Best Practices for Commit Management

  1. Using clear and descriptive titles: Use titles that clearly describe the changes in the commit in clear and concise manner. One look at the message should tell you why the commit was made

  2. Add a detailed body when necessary: For complex and big changes create a detailed summary of the changes which should tell the reader what changes have been made to the code and why these changes were made.

  3. Reference issue tracker IDs: If you are using issue trackers include references of the isuues id in the commit message

  4. Use a particular style: Decide on a perticular pattern or style of writing the commits and use it in your project.

Using branches effectively for feature development and testing

  1. Master and development branches: Always keep the master branch clean and deployable and work in seprate development branches

  2. Feature branches: You can write all the code in the development branch if you are working on a small project. For large projects, keep a seprate branch for each featuer

  3. Merge strategies: At regular intervals merge the master branch with the feature branches to keep them up to date and avoid large merge conflicts later on.

  4. Pull requests: always use pull request before merging especially when working as a team or on public projects.

Git cherry-pick command and its uses

Git cherry-pick is a git command that lets you select specific commits from one branch and them apply them to another branch

  1. Selective feature integration: You want to apply a specific commit from one branch to another branch without merging all the changes

  2. Hotfixes: If there a cretical bug in the master branch which needs to fixed immideately and has been fixed in the development branch along with all the other changes then git cherry-pick to fix the bug with merging the whole branch.

DeadSimpleChat

Need Chat API for your website or app

DeadSimpleChat is an Chat API provider

  • Add Scalable Chat to your app in minutes

  • 10 Million Online Concurrent users

  • 99.999% Uptime

  • Moderation features

  • 1-1 Chat

  • Group Chat

  • Fully Customizable

  • Chat API and SDK

  • Pre-Built Chat

Conclusion

Thank you for reading! I hope you liked the article

...



๐Ÿ“Œ How to Undo the Most Recent Local Commits in Git?


๐Ÿ“ˆ 71.1 Punkte

๐Ÿ“Œ Git Squash Commits โ€“ Squashing the Last N Commits into One Commit


๐Ÿ“ˆ 42.92 Punkte

๐Ÿ“Œ Undo Git Add โ€“ How to Remove Added Files in Git


๐Ÿ“ˆ 40.28 Punkte

๐Ÿ“Œ A clean Git history with Git Rebase and Conventional Commits


๐Ÿ“ˆ 35.67 Punkte

๐Ÿ“Œ [OC]Linux kernel commits as of 5.7-rc1 by author's email domain name,for domains with >= 5000 commits.


๐Ÿ“ˆ 33.44 Punkte

๐Ÿ“Œ [OC]Linux kernel commits as of 5.7-rc1 by author's email domain name,for domains with >= 5000 commits.


๐Ÿ“ˆ 33.44 Punkte

๐Ÿ“Œ How to undo a git push


๐Ÿ“ˆ 30.8 Punkte

๐Ÿ“Œ Two ways to undo changes in Git and when to use each


๐Ÿ“ˆ 30.8 Punkte

๐Ÿ“Œ How to Undo a Particular Commit in Git thatโ€™s Been Pushed to Remote Repos


๐Ÿ“ˆ 30.8 Punkte

๐Ÿ“Œ โช 4 Ways to Undo a Git Commit - Amend vs Reset


๐Ÿ“ˆ 30.8 Punkte

๐Ÿ“Œ git switch and git checkout โ€“ How to switch branches in git


๐Ÿ“ˆ 28.43 Punkte

๐Ÿ“Œ Windows Switch To Git Almost Complete: 8,500 Commits and 1,760 Builds Each Day


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Mystery Git ransomware appears to blank commits, demands Bitcoin to rescue code


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Enhance your git log with conventional commits


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ The Linux kernel has surpassed one million git commits


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ How to Use SSH Keys and 1Password to Sign Git Commits


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Git Log: Die Commits eines Projekts auflisten und durchsuchen


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Split a commit into 2 commits with `git rebase`


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Get a List of All Git Commits Including the Lost Ones


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ How to Squash Commits in Git After They Have Been Pushed?


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Move Commits Between Branches in Git - 3 Different Methods ๐Ÿ’


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ How to Revert a Range of Commits in Git


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Simplify Your Dev Life with Git, SSH & GPG: How to Work with Multiple Code Hosts and Sign Your Commits with Ease


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Signatur-Lรถsung fรผr Git-Commits von Keeper Security - Dev-Insider


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ How to Use Git Cherry Pick and Avoid Duplicate Commits


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Verifying Git commits using GPG


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Enhance your git log with conventional commits


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Git: The complete guide to sign your commits with an ssh key


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Squashing Git Commits for a Cleaner Commit History


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Mastering Git with ChatGPT โ€” best auto-commits you've ever seen


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ How atomic Git commits dramatically increased my productivity - and will increase yours too


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ The Power of Atomic Commits in Git: How and Why to Do It


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ git commit --amend | Domina tu historial de commits.


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Creating "Past" Commits in Git โณ


๐Ÿ“ˆ 26.2 Punkte

๐Ÿ“Œ Investigating FBI Director Comeyโ€™s Actions Canโ€™t Undo the Past


๐Ÿ“ˆ 21.33 Punkte











matomo