Skip to content

Commit

Permalink
docs(blog): update diff post
Browse files Browse the repository at this point in the history
  • Loading branch information
necatiozmen committed Jul 29, 2024
1 parent 013e975 commit df536d1
Showing 1 changed file with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ description: We'll explore Git's 'git diff' which helps you track changes throug
slug: git-diff-command
authors: muhammad_khabbab
tags: [git, dev-tools]
image: https://refine.ams3.cdn.digitaloceanspaces.com/blog/2023-05-12-git-diff/social.png
image: https://refine.ams3.cdn.digitaloceanspaces.com/blog/2023-05-12-git-diff/social-2.png
hide_table_of_contents: false
---

_This article was last updated on July 29, 2024, to add sections for security and using Git Diff with other Git Commands._

## Introduction

Git can be thrilling and, at the same time, intimidating as well. Don't worry, we are here to make things easier for you. Today, we're exploring Git's '`git diff'` command, which developers use on a daily basis.
Expand Down Expand Up @@ -399,12 +401,58 @@ You can use commit hash to compare different commits using git Diff (Sample Belo

<br/>

<br/>
<div>
<a href="https://discord.gg/refine">
<img src="https://refine.ams3.cdn.digitaloceanspaces.com/website/static/img/discord_big_blue.png" alt="discord banner" />
</a>
</div>
### Using `--base` with Git Diff

Merge conflicts mostly arise when several developers work on the same codebase. Running `git diff` can point out conflicting changes and help you address them smoothly:

```sh
git diff --base file.txt
```

This command compares the conflicting file with the base version, making the conflicts clearer to understand and solve.

By the insertion of these additional sections, this article is going to be a more complete guide on how to use `git diff`, which I believe should not only deal with technical usage but practical application.

## Security Features with Git Diff

Now, I'd like to share a few thoughts on the security measures we can put in place to enhance our Git workflow:

### Pre-commit Ho

I will be able to use Git hooks in order to make automatic checks of security issues before commits. For instance, pre-commit hooks can check for sensitive data such as API keys or passwords.

```bash
# .git/hooks
if grep -q "API_KEY" *.js; then
echo "API keys found in the code. Please remove before commit."
exit 1
fi
```

### Commit Signing

We can sign our commits even with GPG keys, making sure that our commits are authentic and helping in the verification of the trusted source of commits.

```bash
git config --global user.signingkey YOUR-GPG-KEY-ID
git commit -S -m "Your commit message"
```

### Regular Audits

Periodic auditing of the codebase can be done through the use of the `git diff` tool to identify any security glitches in the code and fix them during checks. We get to see what changes are brought in and what is fishy.

```bash
git diff HEAD~5
```

The previous 5 commits are compared to the state currently being looked at, to review changes within recent history.

### Access Controls

The access controls on our repositories need to be strict, in a manner such that only the rightly authorized people possess the capability of pushing changes. This can be governed within GitHub and GitLab access controls and other hosting services for Git.

Those are the steps that can help us maintain a more secure codebase and prevent a potential breach of security.

## Conclusion

Expand Down

0 comments on commit df536d1

Please sign in to comment.