Git storify (3) (#1942)
This commit is contained in:
@ -10,11 +10,17 @@ excerpt: Effortlessly create upstream branches on push by enabling a simple git
|
||||
dateModified: 2023-05-21T05:00:00-04:00
|
||||
---
|
||||
|
||||
Manually creating upstream branches on push can be a tedious task. Luckily, Git provides a way to automate this process. You can use `git config` to enable automatic upstream branch creation on push:
|
||||
Manually creating upstream branches on push can be a tedious task. Luckily, Git provides a way to automate this process. You can use `git config` to enable **automatic upstream branch creation on push**:
|
||||
|
||||
```shell
|
||||
git config [--global] --add --bool push.autoSetupRemote true
|
||||
# Syntax: git config [--global] --add --bool push.autoSetupRemote true
|
||||
|
||||
git config --global --add --bool push.autoSetupRemote true
|
||||
# `git push` will automatically create new branches, if they don't exist
|
||||
|
||||
git checkout -b my-branch
|
||||
git push
|
||||
# Pushes to origin/my-branch
|
||||
```
|
||||
|
||||
Using `push.autoSetupRemote` will automatically create a new branch on the remote repository, if it doesn't exist. Workflows that benefit most from this setup are ones where local branches are expected to have the same name as their remote counterparts. You can use the `--global` flag to enable this setting globally on your machine.
|
||||
|
||||
@ -1,22 +1,37 @@
|
||||
---
|
||||
title: Find branches containing a commit
|
||||
type: snippet
|
||||
title: "Tip: Find branches containing a specific Git commit"
|
||||
shortTitle: Find branches containing commit
|
||||
type: tip
|
||||
language: git
|
||||
tags: [branch,commit]
|
||||
author: chalarangelo
|
||||
cover: dark-leaves
|
||||
dateModified: 2021-04-13T21:10:59+03:00
|
||||
excerpt: Learn how to filter branches based on whether they contain a specific commit or not.
|
||||
dateModified: 2023-05-25T21:10:59+03:00
|
||||
---
|
||||
|
||||
Prints all the branches containing a specific commit.
|
||||
Commits are the building blocks of Git, used to track changes to a repository. They can be used to identify specific points in a repository's history, and can be referenced by their commit hash. But apart from finding a commit, how can you find all the branches containing it? This sort of information can be useful when you want to find out which branches contain a specific bugfix or feature.
|
||||
|
||||
- Use `git branch --contains <commit>` to see a list of all branches containing `<commit>`.
|
||||
### Branches that contain a commit
|
||||
|
||||
As usual, Git has a simple solution to this problem. Using `git branch` with the `--contains` flag will print all the **branches containing a specific commit**.
|
||||
|
||||
```shell
|
||||
git branch --contains <commit>
|
||||
# Syntax: git branch --contains <commit>
|
||||
|
||||
git branch --contains 3050fc0
|
||||
# development
|
||||
# network-fixes
|
||||
```
|
||||
|
||||
### Branches that don't contain a commit
|
||||
|
||||
Similarly, you can look for **branches that don't contain a specific commit** by using the `--no-contains` flag.
|
||||
|
||||
```shell
|
||||
git branch --contains 3050fc0d3
|
||||
# patch-1
|
||||
# patch-2
|
||||
# Syntax: git branch --no-contains <commit>
|
||||
|
||||
git branch --no-contains 3050fc0
|
||||
# master
|
||||
# adapter-feature
|
||||
```
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
---
|
||||
title: Find branches not containing a commit
|
||||
type: snippet
|
||||
language: git
|
||||
tags: [branch,commit]
|
||||
cover: blue-sunrise
|
||||
dateModified: 2021-04-13T21:10:59+03:00
|
||||
---
|
||||
|
||||
Prints all the branches not containing a specific commit.
|
||||
|
||||
- Use `git branch --no-contains <commit>` to see a list of all branches not containing `<commit>`.
|
||||
|
||||
```shell
|
||||
git branch --no-contains <commit>
|
||||
```
|
||||
|
||||
```shell
|
||||
git branch --no-contains 3050fc0d3
|
||||
# patch-3
|
||||
# patch-4
|
||||
```
|
||||
@ -1,25 +0,0 @@
|
||||
---
|
||||
title: Change the last commit's author
|
||||
type: snippet
|
||||
language: git
|
||||
tags: [commit]
|
||||
author: chalarangelo
|
||||
cover: symmetry-cloudy-mountain
|
||||
dateModified: 2022-05-03T05:00:00-04:00
|
||||
---
|
||||
|
||||
Updates the last commit's author without changing its contents.
|
||||
|
||||
- Use `git commit --amend` to edit the last commit.
|
||||
- Use the `--author` option to change the `<name>` and `<email>` of the commit's author.
|
||||
|
||||
```shell
|
||||
git commit --amend --author="<name> <email>"
|
||||
```
|
||||
|
||||
```shell
|
||||
# Make some changes to files
|
||||
git add .
|
||||
git commit --amend --author="Duck Quackers <cool.duck@qua.ck>"
|
||||
# The last commit's author is now `Duck Quackers`
|
||||
```
|
||||
@ -1,24 +0,0 @@
|
||||
---
|
||||
title: Create a commit by a different author
|
||||
type: snippet
|
||||
language: git
|
||||
tags: [commit]
|
||||
cover: new-plant
|
||||
dateModified: 2021-04-13T21:10:59+03:00
|
||||
---
|
||||
|
||||
Creates a new commit by the specified author.
|
||||
|
||||
- Use `git commit -m <message>` to create a new commit with the specified `<message>`.
|
||||
- Use the `--author` option to change the `<name>` and `<email>` of the commit's author.
|
||||
|
||||
```shell
|
||||
git commit -m <message> --author="<name> <email>"
|
||||
```
|
||||
|
||||
```shell
|
||||
# Make some changes to files
|
||||
git add .
|
||||
git commit -m "Fix the network bug" --author="Duck Quackers <cool.duck@qua.ck>"
|
||||
# Creates a commit by `Duck Quackers`
|
||||
```
|
||||
52
snippets/git/s/set-or-amend-commit-author.md
Normal file
52
snippets/git/s/set-or-amend-commit-author.md
Normal file
@ -0,0 +1,52 @@
|
||||
---
|
||||
title: Create a commit by a different author in Git
|
||||
shortTitle: Set or amend commit author
|
||||
type: story
|
||||
language: git
|
||||
tags: [commit]
|
||||
author: chalarangelo
|
||||
cover: new-plant
|
||||
excerpt: Ever wanted to commit as someone else? Maybe change the author of an existing commit? Here's how.
|
||||
dateModified: 2023-05-24T21:10:59+03:00
|
||||
---
|
||||
|
||||
Every Git commit is associated with an author, usually configured globally on your machine. But what if you want to commit as someone else? What can you do in case your Git configuration is wrong or you want to use a different email for a specific commit? And what can you do if you've already made a commit and want to change its author?
|
||||
|
||||
### Create a commit by a different author
|
||||
|
||||
As long as you have the author's information, you can create a commit by them. Using the `--author` option for `git commit` will allow you to **create a new commit by a different author**.
|
||||
|
||||
```shell
|
||||
# Syntax: git commit --author="<name> <email>"
|
||||
|
||||
# Make some changes to files
|
||||
git add .
|
||||
git commit -m "Fix the network bug" --author="Duck Quackers <cool.duck@qua.ck>"
|
||||
# Creates a commit by `Duck Quackers`
|
||||
```
|
||||
|
||||
### Change the last commit's author
|
||||
|
||||
In case you want to **change the author of the last commit**, you only need to add the `--amend` flag to the previous command. You can learn more about updating commits in [our guide on amending commits](/git/s/update-commit-message-or-contents).
|
||||
|
||||
```shell
|
||||
# Syntax: git commit --amend --author="<name> <email>"
|
||||
|
||||
# Make some changes to files
|
||||
git add .
|
||||
git commit -m "Fix the network bug" --author="Duck Quackers <cool.duck@qua.ck>"
|
||||
# Creates a commit by `Duck Quackers`
|
||||
|
||||
# Edit or add files
|
||||
git add .
|
||||
git commit --amend --author="Quack Duckers <ducky-o@qua.ck>"
|
||||
# The last commit is now updated and the author is `Quack Duckers`
|
||||
```
|
||||
|
||||
### Caveats
|
||||
|
||||
Changing the author of a commit will also change its **SHA-1 checksum**. If you've already pushed the commit to a remote repository, you will need to force push the updated commit to the remote.
|
||||
|
||||
Additionally, if your remote repository is configured to only accept **signed commits**, you might be unable to sign the commit unless you have the original author's GPG key.
|
||||
|
||||
Finally, you can't use `--author` to add **multiple authors** to a commit. If you want to do so, you can find more information in [the relevant snippet](/git/s/github-co-authors).
|
||||
@ -10,7 +10,7 @@ excerpt: Learn how to view your "undo" history using git reflog and reset your r
|
||||
dateModified: 2023-05-21T21:10:59+03:00
|
||||
---
|
||||
|
||||
Sometimes, `git log` doesn't cut it, especially for commands that don't show up in your commit history. Fortunately, there's a way to view your "undo" history. `reflog` is basically your safety net after running "scary" commands like `git rebase`. It allows you to see not only the commits you made, but each of the actions that led you there.
|
||||
Sometimes, `git log` doesn't cut it, especially for commands that don't show up in your commit history. Fortunately, there's a way to view your **"undo" history**. `reflog` is basically your safety net after running "scary" commands like `git rebase`. It allows you to see not only the commits you made, but each of the actions that led you there.
|
||||
|
||||
To view you "undo" history, you can use `git reflog`, which displays the git reference log:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user