QuestionId stringlengths 3 8 | QuestionTitle stringlengths 15 149 | QuestionScore int64 1 27.2k | QuestionCreatedUtc stringdate 2008-08-01 18:33:08 2025-06-16 04:59:48 | QuestionBodyHtml stringlengths 40 28.2k | QuestionViewCount int64 78 16.5M | QuestionOwnerUserId float64 4 25.2M ⌀ | QuestionLastActivityUtc stringdate 2008-09-08 19:26:01 2026-01-24 22:40:25 | AcceptedAnswerId int64 266 79.7M | AnswerScore int64 2 30.1k | AnswerCreatedUtc stringdate 2008-08-01 23:40:28 2025-06-16 05:23:39 | AnswerOwnerUserId float64 1 29.5M ⌀ | AnswerLastActivityUtc stringdate 2008-08-01 23:40:28 2026-01-23 17:46:09 | QuestionLink stringlengths 31 36 | AnswerLink stringlengths 31 36 | AnswerBodyHtml stringlengths 35 33k | AnswerBodyPreview stringlengths 35 400 | AllTagIdsCsv stringlengths 2 37 | AllTagNamesCsv stringlengths 2 106 | MergedQuestion stringlengths 74 28.4k | quality_filter stringclasses 10
values | unique_id int64 0 29k | tag_major_lang stringclasses 10
values | MergedQuestion_md stringlengths 60 28.1k | AnswerBodyHtml_md stringlengths 14 29.2k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1394797 | Move existing, uncommitted work to a new branch in Git | 4,035 | 2009-09-08 15:57:05 | <p>I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. </p>
<p>How do I move the existing uncommitted changes to a new branch and reset my current one?</p>
<p>I want to reset my current branch while preserving existing work on the new feature.</p>
| 1,183,431 | 1,946 | 2024-04-10 15:21:43 | 1,394,804 | 4,732 | 2009-09-08 15:59:03 | 112,968 | 2021-10-25 15:39:22 | https://stackoverflow.com/q/1394797 | https://stackoverflow.com/a/1394804 | <h3>Update 2020 / Git 2.23</h3>
<p>Git 2.23 adds the new <a href="https://git-scm.com/docs/git-switch" rel="noreferrer"><code>switch</code></a> subcommand in an attempt to clear some of the confusion that comes from the overloaded usage of <a href="https://git-scm.com/docs/git-checkout" rel="noreferrer"><code>checkout<... | <h3>Update 2020 / Git 2.23</h3> <p>Git 2.23 adds the new <a href="https://git-scm.com/docs/git-switch" rel="noreferrer"><code>switch</code></a> subcommand in an attempt to clear some of the confusion that comes from the overloaded usage of <a href="https://git-scm.com/docs/git-checkout" rel="noreferrer"><code>checkout<... | 119, 13091, 51381, 76220 | git, git-branch, git-reset, git-stash | <h1>Move existing, uncommitted work to a new branch in Git</h1>
<p>I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. </p>
<p>How do I move the existing uncommitted changes to a new branch and reset my current one?</p>
<p>I want to reset my current bra... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,745 | git | # Move existing, uncommitted work to a new branch in Git
I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch.
How do I move the existing uncommitted changes to a new branch and reset my current one?
I want to reset my current branch while preserving exi... | ### Update 2020 / Git 2.23
Git 2.23 adds the new [`switch`](https://git-scm.com/docs/git-switch) subcommand in an attempt to clear some of the confusion that comes from the overloaded usage of [`checkout`](https://git-scm.com/docs/git-checkout) (switching branches, restoring files, detaching HEAD, etc.)
Starting with... |
7229885 | What are the differences between .gitignore and .gitkeep? | 2,696 | 2011-08-29 12:11:05 | <p>What are the differences between <code>.gitignore</code> and <code>.gitkeep</code>? Are they the same thing with a different name, or do they both serve a different function?</p>
<p>I don't seem to be able to find much documentation on <code>.gitkeep</code>.</p>
| 675,307 | 509,271 | 2025-06-17 15:08:14 | 7,229,996 | 4,661 | 2011-08-29 12:20:54 | 110,707 | 2021-10-21 14:16:07 | https://stackoverflow.com/q/7229885 | https://stackoverflow.com/a/7229996 | <p><code>.gitkeep</code> isn’t documented, because it’s not a feature of Git.</p>
<p>Git <a href="https://git.wiki.kernel.org/index.php/Git_FAQ#Can_I_add_empty_directories.3F" rel="noreferrer">cannot add a completely empty directory</a>. People who want to track empty directories in Git have created the convention of p... | <p><code>.gitkeep</code> isn’t documented, because it’s not a feature of Git.</p> <p>Git <a href="https://git.wiki.kernel.org/index.php/Git_FAQ#Can_I_add_empty_directories.3F" rel="noreferrer">cannot add a completely empty directory</a>. People who want to track empty directories in Git have created the convention of p... | 119, 25056 | git, gitignore | <h1>What are the differences between .gitignore and .gitkeep?</h1>
<p>What are the differences between <code>.gitignore</code> and <code>.gitkeep</code>? Are they the same thing with a different name, or do they both serve a different function?</p>
<p>I don't seem to be able to find much documentation on <code>.gitkee... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,746 | git | # What are the differences between .gitignore and .gitkeep?
What are the differences between `.gitignore` and `.gitkeep`? Are they the same thing with a different name, or do they both serve a different function?
I don't seem to be able to find much documentation on `.gitkeep`. | `.gitkeep` isn’t documented, because it’s not a feature of Git.
Git [cannot add a completely empty directory](https://git.wiki.kernel.org/index.php/Git_FAQ#Can_I_add_empty_directories.3F). People who want to track empty directories in Git have created the convention of putting files called `.gitkeep` in these director... |
1186535 | How do I modify a specific commit? | 3,365 | 2009-07-27 05:19:07 | <p>I have the following commit history:</p>
<ol>
<li><code>HEAD</code></li>
<li><code>HEAD~</code></li>
<li><code>HEAD~2</code></li>
<li><code>HEAD~3</code></li>
</ol>
<p><code>git commit --amend</code> modifies the current <code>HEAD</code> commit. But how do I modify <code>HEAD~3</code>?</p>
| 1,793,294 | 75,501 | 2025-05-11 07:16:09 | 1,186,549 | 4,648 | 2009-07-27 05:28:02 | 111,896 | 2023-06-04 07:34:57 | https://stackoverflow.com/q/1186535 | https://stackoverflow.com/a/1186549 | <p>Use <a href="https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase" rel="noreferrer"><code>git rebase</code></a>. For example, to modify commit <code>bbc643cd</code>, run:</p>
<pre class="lang-bash prettyprint-override"><code>git rebase --interactive bbc643cd~
</code></pre>
<p>Please note the tilde <c... | <p>Use <a href="https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase" rel="noreferrer"><code>git rebase</code></a>. For example, to modify commit <code>bbc643cd</code>, run:</p> <pre class="lang-bash prettyprint-override"><code>git rebase --interactive bbc643cd~ </code></pre> <p>Please note the tilde <c... | 119, 91259 | git, git-rewrite-history | <h1>How do I modify a specific commit?</h1>
<p>I have the following commit history:</p>
<ol>
<li><code>HEAD</code></li>
<li><code>HEAD~</code></li>
<li><code>HEAD~2</code></li>
<li><code>HEAD~3</code></li>
</ol>
<p><code>git commit --amend</code> modifies the current <code>HEAD</code> commit. But how do I modify <code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,747 | git | # How do I modify a specific commit?
I have the following commit history:
1. `HEAD`
2. `HEAD~`
3. `HEAD~2`
4. `HEAD~3`
`git commit --amend` modifies the current `HEAD` commit. But how do I modify `HEAD~3`? | Use [`git rebase`](https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase). For example, to modify commit `bbc643cd`, run:
```
git rebase --interactive bbc643cd~
```
Please note the tilde `~` at the end of the command, because you need to reapply commits on top of the previous commit of `bbc643cd` (i.e.... |
35942754 | How can I save username and password in Git? | 2,832 | 2016-03-11 14:29:37 | <p>I want to use a push and pull automatically in <em><a href="http://gitextensions.github.io/" rel="noreferrer">Git Extensions</a></em>, <em><a href="https://en.wikipedia.org/wiki/Atlassian#Acquisitions_and_product_announcements" rel="noreferrer">Sourcetree</a></em> or any other Git GUI without entering my username an... | 4,728,282 | 3,511,668 | 2025-01-16 12:29:18 | 35,942,890 | 4,552 | 2016-03-11 14:36:13 | 5,574,889 | 2024-06-14 07:39:58 | https://stackoverflow.com/q/35942754 | https://stackoverflow.com/a/35942890 | <h2>Attention:</h2>
<p>This method saves the credentials in <strong>plaintext</strong> on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.</p>
<p><strong>Run</strong>:</p>
<pre><code>git config --global credential.helper store
</code></pre>
<p><strong>then</strong>:</p>
<pre><code>gi... | <h2>Attention:</h2> <p>This method saves the credentials in <strong>plaintext</strong> on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.</p> <p><strong>Run</strong>:</p> <pre><code>git config --global credential.helper store </code></pre> <p><strong>then</strong>:</p> <pre><code>gi... | 119, 5357, 32868, 39597 | credentials, git, git-config, git-extensions | <h1>How can I save username and password in Git?</h1>
<p>I want to use a push and pull automatically in <em><a href="http://gitextensions.github.io/" rel="noreferrer">Git Extensions</a></em>, <em><a href="https://en.wikipedia.org/wiki/Atlassian#Acquisitions_and_product_announcements" rel="noreferrer">Sourcetree</a></em... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,748 | git | # How can I save username and password in Git?
I want to use a push and pull automatically in *[Git Extensions](http://gitextensions.github.io/)*, *[Sourcetree](https://en.wikipedia.org/wiki/Atlassian#Acquisitions_and_product_announcements)* or any other Git GUI without entering my username and password in a prompt, e... | ## Attention:
This method saves the credentials in **plaintext** on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.
**Run**:
```
git config --global credential.helper store
```
**then**:
```
git pull
```
provide a username and password and those details will then be remembered... |
6245570 | How do I get the current branch name in Git? | 4,270 | 2011-06-05 20:13:43 | <p>How do I get the name of the current branch in Git?</p>
| 3,769,106 | null | 2026-01-10 17:41:36 | 6,245,587 | 4,519 | 2011-06-05 20:17:04 | 675,618 | 2023-07-20 10:28:15 | https://stackoverflow.com/q/6245570 | https://stackoverflow.com/a/6245587 | <pre><code>git branch
</code></pre>
<p>should show all the local branches of your repo. The starred branch is your current branch.</p>
<hr />
<p>To retrieve only the name of the branch you are on:</p>
<pre><code>git rev-parse --abbrev-ref HEAD
</code></pre>
<p>Version 2.22 adds the <code>--show-current</code> option to... | <pre><code>git branch </code></pre> <p>should show all the local branches of your repo. The starred branch is your current branch.</p> <hr /> <p>To retrieve only the name of the branch you are on:</p> <pre><code>git rev-parse --abbrev-ref HEAD </code></pre> <p>Version 2.22 adds the <code>--show-current</code> option to... | 119, 1879, 76220 | branch, git, git-branch | <h1>How do I get the current branch name in Git?</h1>
<p>How do I get the name of the current branch in Git?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,749 | git | # How do I get the current branch name in Git?
How do I get the name of the current branch in Git? | ```
git branch
```
should show all the local branches of your repo. The starred branch is your current branch.
---
To retrieve only the name of the branch you are on:
```
git rev-parse --abbrev-ref HEAD
```
Version 2.22 adds the `--show-current` option to [*”print the name of the current branch”*](https://www.git-... |
651038 | How do I clone a Git repository into a specific folder? | 3,190 | 2009-03-16 15:56:54 | <p>The command <code>git clone git@github.com:whatever</code> creates a directory named <code>whatever</code> containing a Git repository:</p>
<pre><code>./
whatever/
.git
</code></pre>
<p>I want the contents of the Git repository cloned into my current directory <code>./</code> instead:</p>
<pre><code>./
... | 3,358,879 | 78,642 | 2024-09-25 11:48:23 | 651,079 | 4,503 | 2009-03-16 16:08:24 | 2,119 | 2020-09-19 09:42:56 | https://stackoverflow.com/q/651038 | https://stackoverflow.com/a/651079 | <p><strong>Option A:</strong></p>
<pre><code>git clone git@github.com:whatever folder-name
</code></pre>
<p>Ergo, for <code>right here</code> use:</p>
<pre><code>git clone git@github.com:whatever .
</code></pre>
<p><strong>Option B:</strong></p>
<p>Move the <code>.git</code> folder, too. Note that the <code>.git</code>... | <p><strong>Option A:</strong></p> <pre><code>git clone git@github.com:whatever folder-name </code></pre> <p>Ergo, for <code>right here</code> use:</p> <pre><code>git clone git@github.com:whatever . </code></pre> <p><strong>Option B:</strong></p> <p>Move the <code>.git</code> folder, too. Note that the <code>.git</code>... | 119, 7330, 34099 | git, git-clone, repository | <h1>How do I clone a Git repository into a specific folder?</h1>
<p>The command <code>git clone git@github.com:whatever</code> creates a directory named <code>whatever</code> containing a Git repository:</p>
<pre><code>./
whatever/
.git
</code></pre>
<p>I want the contents of the Git repository cloned into ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,750 | git | # How do I clone a Git repository into a specific folder?
The command `git clone git@github.com:whatever` creates a directory named `whatever` containing a Git repository:
```
./
whatever/
.git
```
I want the contents of the Git repository cloned into my current directory `./` instead:
```
./
.git
`... | **Option A:**
```
git clone git@github.com:whatever folder-name
```
Ergo, for `right here` use:
```
git clone git@github.com:whatever .
```
**Option B:**
Move the `.git` folder, too. Note that the `.git` folder is hidden in most graphical file explorers, so be sure to show hidden files.
```
mv /where/it/is/right/... |
2047465 | How do I delete a file from a Git repository? | 2,633 | 2010-01-12 07:48:52 | <p>How can I delete <code>"file1.txt"</code> from my repository?</p>
| 3,620,537 | 246,365 | 2024-10-24 12:06:33 | 2,047,477 | 4,402 | 2010-01-12 07:52:32 | 893 | 2020-06-19 10:02:47 | https://stackoverflow.com/q/2047465 | https://stackoverflow.com/a/2047477 | <p>Use <a href="https://git-scm.com/docs/git-rm" rel="noreferrer"><code>git rm</code></a>.</p>
<p>If you want to remove the file from the Git repository <strong>and the filesystem</strong>, use:</p>
<pre class="lang-sh prettyprint-override"><code>git rm file1.txt
git commit -m "remove file1.txt"
</code></pre>
<p>But... | <p>Use <a href="https://git-scm.com/docs/git-rm" rel="noreferrer"><code>git rm</code></a>.</p> <p>If you want to remove the file from the Git repository <strong>and the filesystem</strong>, use:</p> <pre class="lang-sh prettyprint-override"><code>git rm file1.txt git commit -m "remove file1.txt" </code></pre> <p>But... | 119, 112901 | git, git-rm | <h1>How do I delete a file from a Git repository?</h1>
<p>How can I delete <code>"file1.txt"</code> from my repository?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,751 | git | # How do I delete a file from a Git repository?
How can I delete `"file1.txt"` from my repository? | Use [`git rm`](https://git-scm.com/docs/git-rm).
If you want to remove the file from the Git repository **and the filesystem**, use:
```
git rm file1.txt
git commit -m "remove file1.txt"
```
But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:
```
git rm --cach... |
12481639 | Remove file from latest commit | 2,378 | 2012-09-18 16:59:12 | <p>How do I remove a file from the latest commit?</p>
| 2,467,207 | 646,276 | 2024-01-07 16:09:04 | 15,321,456 | 4,364 | 2013-03-10 10:56:37 | 2,153,571 | 2023-06-01 16:42:55 | https://stackoverflow.com/q/12481639 | https://stackoverflow.com/a/15321456 | <p>I think other answers here are wrong, because this is a question of moving the mistakenly committed files back to the staging area from the previous commit, without cancelling the changes done to them. This can be done like Paritosh Singh suggested:</p>
<pre><code>git reset --soft HEAD^
</code></pre>
<p>or</p>
<pre... | <p>I think other answers here are wrong, because this is a question of moving the mistakenly committed files back to the staging area from the previous commit, without cancelling the changes done to them. This can be done like Paritosh Singh suggested:</p> <pre><code>git reset --soft HEAD^ </code></pre> <p>or</p> <pre... | 119, 53850 | git, git-commit | <h1>Remove file from latest commit</h1>
<p>How do I remove a file from the latest commit?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,752 | git | # Remove file from latest commit
How do I remove a file from the latest commit? | I think other answers here are wrong, because this is a question of moving the mistakenly committed files back to the staging area from the previous commit, without cancelling the changes done to them. This can be done like Paritosh Singh suggested:
```
git reset --soft HEAD^
```
or
```
git reset --soft HEAD~1
```
... |
89332 | How do I recover a dropped stash in Git? | 2,656 | 2008-09-18 01:59:06 | <p>I frequently use <code>git stash</code> and <code>git stash pop</code> to save and restore changes in my working tree. Yesterday, I had some changes in my working tree that I had stashed and popped, and then I made more changes to my working tree. I'd like to go back and review yesterday's stashed changes, but <code... | 641,898 | 893 | 2025-09-28 17:28:08 | 91,795 | 4,355 | 2008-09-18 11:38:25 | 9,410 | 2024-12-30 18:18:24 | https://stackoverflow.com/q/89332 | https://stackoverflow.com/a/91795 | <p>Once you know the hash of the stash commit you dropped, you can apply it as a stash:</p>
<pre class="lang-bash prettyprint-override"><code>git stash apply $stash_hash
</code></pre>
<p>Or, you can create a separate branch for it with</p>
<pre class="lang-bash prettyprint-override"><code>git branch recovered $stash_ha... | <p>Once you know the hash of the stash commit you dropped, you can apply it as a stash:</p> <pre class="lang-bash prettyprint-override"><code>git stash apply $stash_hash </code></pre> <p>Or, you can create a separate branch for it with</p> <pre class="lang-bash prettyprint-override"><code>git branch recovered $stash_ha... | 119, 2200, 13091 | git, git-stash, recovery | <h1>How do I recover a dropped stash in Git?</h1>
<p>I frequently use <code>git stash</code> and <code>git stash pop</code> to save and restore changes in my working tree. Yesterday, I had some changes in my working tree that I had stashed and popped, and then I made more changes to my working tree. I'd like to go back... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,753 | git | # How do I recover a dropped stash in Git?
I frequently use `git stash` and `git stash pop` to save and restore changes in my working tree. Yesterday, I had some changes in my working tree that I had stashed and popped, and then I made more changes to my working tree. I'd like to go back and review yesterday's stashed... | Once you know the hash of the stash commit you dropped, you can apply it as a stash:
```
git stash apply $stash_hash
```
Or, you can create a separate branch for it with
```
git branch recovered $stash_hash
```
After that, you can do whatever you want with all the normal tools. When you’re done, just blow the branc... |
9537392 | `git fetch` a remote branch | 3,231 | 2012-03-02 17:06:56 | <p>The remote repository contains various branches such as <code>origin/daves_branch</code>:</p>
<pre><code>$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/master
</code></pre>
<p>How do I switch to <code>daves_branch</code> in the local repository so that it tracks <code>origin/daves_branch<... | 4,850,336 | 846,381 | 2026-01-04 04:24:36 | 9,537,923 | 4,349 | 2012-03-02 17:45:18 | 106,205 | 2026-01-04 04:24:36 | https://stackoverflow.com/q/9537392 | https://stackoverflow.com/a/9537923 | <h1>Update: Using Git Switch</h1>
<p>All of the information written below was accurate, but a new command, <a href="https://git-scm.com/docs/git-switch" rel="nofollow noreferrer"><code>git switch</code></a> has been added that simplifies the effort.</p>
<p>If <code>daves_branch</code> exists on the remote repository, b... | <h1>Update: Using Git Switch</h1> <p>All of the information written below was accurate, but a new command, <a href="https://git-scm.com/docs/git-switch" rel="nofollow noreferrer"><code>git switch</code></a> has been added that simplifies the effort.</p> <p>If <code>daves_branch</code> exists on the remote repository, b... | 119, 1879, 33720, 76220 | branch, git, git-branch, git-fetch | <h1>`git fetch` a remote branch</h1>
<p>The remote repository contains various branches such as <code>origin/daves_branch</code>:</p>
<pre><code>$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/master
</code></pre>
<p>How do I switch to <code>daves_branch</code> in the local repository so that... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,754 | git | # `git fetch` a remote branch
The remote repository contains various branches such as `origin/daves_branch`:
```
$ git branch -r
origin/HEAD -> origin/master
origin/daves_branch
origin/master
```
How do I switch to `daves_branch` in the local repository so that it tracks `origin/daves_branch`?
I tried:
```
$ git f... | # Update: Using Git Switch
All of the information written below was accurate, but a new command, [`git switch`](https://git-scm.com/docs/git-switch) has been added that simplifies the effort.
If `daves_branch` exists on the remote repository, but not on your local branch, you can simply type:
```
git fetch --all
git... |
9339429 | What does cherry-picking a commit with Git mean? | 3,481 | 2012-02-18 07:20:47 | <p>What does <a href="https://git-scm.com/docs/git-cherry-pick" rel="noreferrer"><code>git cherry-pick <commit></code></a> do?</p>
| 2,724,548 | 826,610 | 2025-12-16 18:33:58 | 9,339,460 | 4,201 | 2012-02-18 07:29:42 | 11,123 | 2023-05-09 08:18:24 | https://stackoverflow.com/q/9339429 | https://stackoverflow.com/a/9339460 | <p>Cherry-picking in Git means choosing a commit from one branch and applying it to another.</p>
<p>This contrasts with other ways such as <code>merge</code> and <code>rebase</code> which normally apply many commits to another branch.</p>
<p>It's also possible to <a href="https://stackoverflow.com/questions/1670970/how... | <p>Cherry-picking in Git means choosing a commit from one branch and applying it to another.</p> <p>This contrasts with other ways such as <code>merge</code> and <code>rebase</code> which normally apply many commits to another branch.</p> <p>It's also possible to <a href="https://stackoverflow.com/questions/1670970/how... | 119, 36489, 78810 | cherry-pick, git, git-cherry-pick | <h1>What does cherry-picking a commit with Git mean?</h1>
<p>What does <a href="https://git-scm.com/docs/git-cherry-pick" rel="noreferrer"><code>git cherry-pick <commit></code></a> do?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,755 | git | # What does cherry-picking a commit with Git mean?
What does [`git cherry-pick <commit>`](https://git-scm.com/docs/git-cherry-pick) do? | Cherry-picking in Git means choosing a commit from one branch and applying it to another.
This contrasts with other ways such as `merge` and `rebase` which normally apply many commits to another branch.
It's also possible to [cherry-pick multiple commits](https://stackoverflow.com/questions/1670970/how-to-cherry-pick... |
949314 | How do I get the hash for the current commit in Git? | 2,843 | 2009-06-04 08:42:51 | <p>How do I get the hash of the current commit in Git?</p>
| 1,790,088 | 33,671 | 2025-03-04 04:15:10 | 949,391 | 4,141 | 2009-06-04 09:05:57 | 46,058 | 2025-03-04 04:15:10 | https://stackoverflow.com/q/949314 | https://stackoverflow.com/a/949391 | <p>To turn any extended object reference into a hash, use <strong><a href="http://git-scm.com/docs/git-rev-parse" rel="noreferrer" title="git-rev-parse - Pick out and massage parameters"><code>git-rev-parse</code></a></strong>:</p>
<pre><code>git rev-parse HEAD
</code></pre>
<p>or</p>
<pre><code>git rev-parse --verify ... | <p>To turn any extended object reference into a hash, use <strong><a href="http://git-scm.com/docs/git-rev-parse" rel="noreferrer" title="git-rev-parse - Pick out and massage parameters"><code>git-rev-parse</code></a></strong>:</p> <pre><code>git rev-parse HEAD </code></pre> <p>or</p> <pre><code>git rev-parse --verify ... | 119, 117987 | git, git-hash | <h1>How do I get the hash for the current commit in Git?</h1>
<p>How do I get the hash of the current commit in Git?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,756 | git | # How do I get the hash for the current commit in Git?
How do I get the hash of the current commit in Git? | To turn any extended object reference into a hash, use **[`git-rev-parse`](http://git-scm.com/docs/git-rev-parse "git-rev-parse - Pick out and massage parameters")**:
```
git rev-parse HEAD
```
or
```
git rev-parse --verify HEAD
```
As noted by Alexander's [answer](https://stackoverflow.com/a/38666663/2411802), you... |
6127328 | How do I delete all Git branches which have been merged? | 2,767 | 2011-05-25 15:54:36 | <p>How do I delete branches which have already been merged? Can I delete them all at once, instead of deleting each branch one-by-one?</p>
| 1,076,647 | 400,275 | 2025-07-30 12:34:06 | 6,127,884 | 4,114 | 2011-05-25 16:40:19 | 1,864,976 | 2024-12-15 14:26:55 | https://stackoverflow.com/q/6127328 | https://stackoverflow.com/a/6127884 | <p>NOTE: You can add other branches to exclude like master and dev if your workflow has those as a possible ancestor. Usually I branch off of a "sprint-start" tag and <code>master</code>, <code>dev</code> and <code>qa</code> are not ancestors.</p>
<hr />
<p>First, list locally-tracking branches that were merg... | <p>NOTE: You can add other branches to exclude like master and dev if your workflow has those as a possible ancestor. Usually I branch off of a "sprint-start" tag and <code>master</code>, <code>dev</code> and <code>qa</code> are not ancestors.</p> <hr /> <p>First, list locally-tracking branches that were merg... | 119, 456, 1879, 40701 | branch, feature-branch, git, version-control | <h1>How do I delete all Git branches which have been merged?</h1>
<p>How do I delete branches which have already been merged? Can I delete them all at once, instead of deleting each branch one-by-one?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,757 | git | # How do I delete all Git branches which have been merged?
How do I delete branches which have already been merged? Can I delete them all at once, instead of deleting each branch one-by-one? | NOTE: You can add other branches to exclude like master and dev if your workflow has those as a possible ancestor. Usually I branch off of a "sprint-start" tag and `master`, `dev` and `qa` are not ancestors.
---
First, list locally-tracking branches that were merged in remote (consider using `-r` flag to list all rem... |
5097456 | Throw away local commits in Git | 2,481 | 2011-02-23 21:33:55 | <p>Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and start over again.</p>
<p>Obviously, deleting my working directory and re-cloning would do it, but downloading everything from GitHub again seems ... | 2,386,972 | 27,358 | 2024-12-27 14:35:28 | 5,097,495 | 3,959 | 2011-02-23 21:38:10 | 479,989 | 2019-04-30 15:01:13 | https://stackoverflow.com/q/5097456 | https://stackoverflow.com/a/5097495 | <p>If your excess commits are only visible to you, you can just do
<code>git reset --hard origin/<branch_name></code>
to move back to where the origin is. This will reset the state of the repository to the previous commit, and it will discard all local changes.</p>
<p>Doing a <code>git revert</code> makes <em>... | <p>If your excess commits are only visible to you, you can just do <code>git reset --hard origin/<branch_name></code> to move back to where the origin is. This will reset the state of the repository to the previous commit, and it will discard all local changes.</p> <p>Doing a <code>git revert</code> makes <em>... | 119 | git | <h1>Throw away local commits in Git</h1>
<p>Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and start over again.</p>
<p>Obviously, deleting my working directory and re-cloning would do it, but downlo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,758 | git | # Throw away local commits in Git
Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and start over again.
Obviously, deleting my working directory and re-cloning would do it, but downloading everything... | If your excess commits are only visible to you, you can just do
`git reset --hard origin/<branch_name>`
to move back to where the origin is. This will reset the state of the repository to the previous commit, and it will discard all local changes.
Doing a `git revert` makes *new* commits to remove *old* commits in a w... |
10725729 | See what's in a stash without applying it | 2,870 | 2012-05-23 18:26:39 | <p>How do I see what is inside a <a href="https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning" rel="noreferrer">stash</a> without actually applying it?</p>
| 1,687,505 | 586,131 | 2024-03-05 20:50:14 | 10,726,185 | 3,956 | 2012-05-23 18:58:49 | 1,084,945 | 2024-03-05 20:50:14 | https://stackoverflow.com/q/10725729 | https://stackoverflow.com/a/10726185 | <p>From <code>man git-stash</code> (which can also be obtained via <code>git help stash</code>):</p>
<blockquote>
<p>The modifications stashed away by this command can be listed with <code>git stash list</code>, inspected with <code>git stash show</code>, and ...</p>
</blockquote>
<pre><code>show [<stash>]
Sh... | <p>From <code>man git-stash</code> (which can also be obtained via <code>git help stash</code>):</p> <blockquote> <p>The modifications stashed away by this command can be listed with <code>git stash list</code>, inspected with <code>git stash show</code>, and ...</p> </blockquote> <pre><code>show [<stash>] Sh... | 119, 13091 | git, git-stash | <h1>See what's in a stash without applying it</h1>
<p>How do I see what is inside a <a href="https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning" rel="noreferrer">stash</a> without actually applying it?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,759 | git | # See what's in a stash without applying it
How do I see what is inside a [stash](https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning) without actually applying it? | From `man git-stash` (which can also be obtained via `git help stash`):
> The modifications stashed away by this command can be listed with `git stash list`, inspected with `git stash show`, and ...
```
show [<stash>]
Show the changes recorded in the stash as a diff between the stashed
state and its original ... |
3796927 | How do I "git clone" a repo, including its submodules? | 2,815 | 2010-09-26 07:13:25 | <p>How do I clone a git repository so that it also clones its submodules?</p>
<p>Running <code>git clone $REPO_URL</code> merely creates empty submodule directories.</p>
| 1,879,877 | null | 2024-08-13 10:28:50 | 4,438,292 | 3,932 | 2010-12-14 10:43:12 | 96,656 | 2018-10-19 06:46:07 | https://stackoverflow.com/q/3796927 | https://stackoverflow.com/a/4438292 | <p>With version 2.13 of Git and later, <code>--recurse-submodules</code> can be used instead of <code>--recursive</code>:</p>
<pre><code>git clone --recurse-submodules -j8 git://github.com/foo/bar.git
cd bar
</code></pre>
<p><sup>Editor’s note: <code>-j8</code> is an optional performance optimization that became avai... | <p>With version 2.13 of Git and later, <code>--recurse-submodules</code> can be used instead of <code>--recursive</code>:</p> <pre><code>git clone --recurse-submodules -j8 git://github.com/foo/bar.git cd bar </code></pre> <p><sup>Editor’s note: <code>-j8</code> is an optional performance optimization that became avai... | 119, 41612 | git, git-submodules | <h1>How do I "git clone" a repo, including its submodules?</h1>
<p>How do I clone a git repository so that it also clones its submodules?</p>
<p>Running <code>git clone $REPO_URL</code> merely creates empty submodule directories.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,760 | git | # How do I "git clone" a repo, including its submodules?
How do I clone a git repository so that it also clones its submodules?
Running `git clone $REPO_URL` merely creates empty submodule directories. | With version 2.13 of Git and later, `--recurse-submodules` can be used instead of `--recursive`:
```
git clone --recurse-submodules -j8 git://github.com/foo/bar.git
cd bar
```
Editor’s note: `-j8` is an optional performance optimization that became available in version 2.8, and fetches up to 8 submodules at a time in... |
2816715 | How to branch from a previous commit | 2,736 | 2010-05-12 07:21:55 | <p>If I have an <code>n</code> number of commits, how can I create a branch from the <code>n-3</code> commit?</p>
| 1,466,863 | 86,112 | 2025-04-17 21:19:39 | 2,816,728 | 3,902 | 2010-05-12 07:24:18 | 19,563 | 2022-07-25 02:40:56 | https://stackoverflow.com/q/2816715 | https://stackoverflow.com/a/2816728 | <p>Create the branch using a commit hash:</p>
<pre><code>git branch branch_name <commit-hash>
</code></pre>
<p>Or by using a symbolic reference:</p>
<pre><code>git branch branch_name HEAD~3
</code></pre>
<p>To checkout the branch while creating it, use:</p>
<pre><code>git checkout -b branch_name <commit-hash o... | <p>Create the branch using a commit hash:</p> <pre><code>git branch branch_name <commit-hash> </code></pre> <p>Or by using a symbolic reference:</p> <pre><code>git branch branch_name HEAD~3 </code></pre> <p>To checkout the branch while creating it, use:</p> <pre><code>git checkout -b branch_name <commit-hash o... | 119, 1879, 5597, 76220 | branch, commit, git, git-branch | <h1>How to branch from a previous commit</h1>
<p>If I have an <code>n</code> number of commits, how can I create a branch from the <code>n-3</code> commit?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,761 | git | # How to branch from a previous commit
If I have an `n` number of commits, how can I create a branch from the `n-3` commit? | Create the branch using a commit hash:
```
git branch branch_name <commit-hash>
```
Or by using a symbolic reference:
```
git branch branch_name HEAD~3
```
To checkout the branch while creating it, use:
```
git checkout -b branch_name <commit-hash or HEAD~3>
``` |
1030169 | Pull latest changes for all git submodules | 2,797 | 2009-06-23 01:05:54 | <p>We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest version of every dependent submodule.</p>
<p>... | 2,306,380 | 77,002 | 2025-04-11 21:36:53 | 1,032,653 | 3,874 | 2009-06-23 13:42:29 | 2,010 | 2020-03-11 05:48:39 | https://stackoverflow.com/q/1030169 | https://stackoverflow.com/a/1032653 | <p>If it's <strong>the first time</strong> you check-out a repo you need to use <code>--init</code> first:</p>
<pre><code>git submodule update --init --recursive
</code></pre>
<p>For <strong>git 1.8.2</strong> or above, the option <code>--remote</code> was added to support updating to latest tips of remote branches:<... | <p>If it's <strong>the first time</strong> you check-out a repo you need to use <code>--init</code> first:</p> <pre><code>git submodule update --init --recursive </code></pre> <p>For <strong>git 1.8.2</strong> or above, the option <code>--remote</code> was added to support updating to latest tips of remote branches:<... | 119, 41612 | git, git-submodules | <h1>Pull latest changes for all git submodules</h1>
<p>We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,762 | git | # Pull latest changes for all git submodules
We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest ve... | If it's **the first time** you check-out a repo you need to use `--init` first:
```
git submodule update --init --recursive
```
For **git 1.8.2** or above, the option `--remote` was added to support updating to latest tips of remote branches:
```
git submodule update --recursive --remote
```
This has the added bene... |
11369375 | How can I delete all of my Git stashes at once? | 2,245 | 2012-07-06 20:38:58 | <p>How can I delete all of my <a href="https://en.wikipedia.org/wiki/Git" rel="noreferrer">Git</a> stashes at once?</p>
<p>Specifically I mean, with typing in one command.</p>
| 824,071 | 2,183,673 | 2024-07-09 11:26:53 | 11,369,406 | 3,823 | 2012-07-06 20:41:39 | 548,696 | 2019-08-09 02:19:58 | https://stackoverflow.com/q/11369375 | https://stackoverflow.com/a/11369406 | <p>The following command deletes all your stashes:</p>
<pre><code>git stash clear
</code></pre>
<p>From the <a href="http://www.kernel.org/pub/software/scm/git/docs/git-stash.html" rel="noreferrer">git documentation</a>:</p>
<blockquote>
<p><strong><code>clear</code></strong></p>
<p>Remove all the stashed states.</p>
<... | <p>The following command deletes all your stashes:</p> <pre><code>git stash clear </code></pre> <p>From the <a href="http://www.kernel.org/pub/software/scm/git/docs/git-stash.html" rel="noreferrer">git documentation</a>:</p> <blockquote> <p><strong><code>clear</code></strong></p> <p>Remove all the stashed states.</p> <... | 119, 13091 | git, git-stash | <h1>How can I delete all of my Git stashes at once?</h1>
<p>How can I delete all of my <a href="https://en.wikipedia.org/wiki/Git" rel="noreferrer">Git</a> stashes at once?</p>
<p>Specifically I mean, with typing in one command.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,763 | git | # How can I delete all of my Git stashes at once?
How can I delete all of my [Git](https://en.wikipedia.org/wiki/Git) stashes at once?
Specifically I mean, with typing in one command. | The following command deletes all your stashes:
```
git stash clear
```
From the [git documentation](http://www.kernel.org/pub/software/scm/git/docs/git-stash.html):
> **`clear`**
>
> Remove all the stashed states.
>
> **IMPORTANT WARNING:** Those states will then be subject to pruning, and may be impossible to reco... |
5601931 | How do I safely merge a Git branch into master? | 2,723 | 2011-04-09 00:01:01 | <p>A new branch from <code>master</code> is created, we call it <code>test</code>.</p>
<p>There are several developers who either commit to <code>master</code> or create other branches and later merge into <code>master</code>.</p>
<p>Let's say work on <code>test</code> is taking several days and you want to continuou... | 2,437,447 | 647,794 | 2025-11-18 15:10:18 | 5,602,109 | 3,741 | 2011-04-09 00:45:29 | 421,223 | 2016-06-15 00:02:20 | https://stackoverflow.com/q/5601931 | https://stackoverflow.com/a/5602109 | <p>How I would do this</p>
<pre><code>git checkout master
git pull origin master
git merge test
git push origin master
</code></pre>
<p>If I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also I would not push my changes, until I'm happy with... | <p>How I would do this</p> <pre><code>git checkout master git pull origin master git merge test git push origin master </code></pre> <p>If I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also I would not push my changes, until I'm happy with... | 119, 28897, 53847, 76220 | branching-and-merging, git, git-branch, git-merge | <h1>How do I safely merge a Git branch into master?</h1>
<p>A new branch from <code>master</code> is created, we call it <code>test</code>.</p>
<p>There are several developers who either commit to <code>master</code> or create other branches and later merge into <code>master</code>.</p>
<p>Let's say work on <code>tes... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,764 | git | # How do I safely merge a Git branch into master?
A new branch from `master` is created, we call it `test`.
There are several developers who either commit to `master` or create other branches and later merge into `master`.
Let's say work on `test` is taking several days and you want to continuously keep `test` updat... | How I would do this
```
git checkout master
git pull origin master
git merge test
git push origin master
```
If I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also I would not push my changes, until I'm happy with what I want to push and al... |
2510276 | How do I undo 'git reset'? | 2,079 | 2010-03-24 18:08:29 | <p>How do I undo this command?</p>
<pre><code>git reset HEAD~
</code></pre>
| 1,084,901 | 74,865 | 2025-08-26 13:35:42 | 2,531,803 | 3,738 | 2010-03-28 03:32:52 | 303,425 | 2024-01-15 19:50:58 | https://stackoverflow.com/q/2510276 | https://stackoverflow.com/a/2531803 | <h3>Short answer:</h3>
<pre class="lang-bash prettyprint-override"><code>git reset 'HEAD@{1}'
</code></pre>
<h3>Long answer:</h3>
<p>Git keeps a log of all ref updates (e.g., checkout, reset, commit, merge). You can view it by typing:</p>
<pre><code>git reflog
</code></pre>
<p>Somewhere in this list is the commit that ... | <h3>Short answer:</h3> <pre class="lang-bash prettyprint-override"><code>git reset 'HEAD@{1}' </code></pre> <h3>Long answer:</h3> <p>Git keeps a log of all ref updates (e.g., checkout, reset, commit, merge). You can view it by typing:</p> <pre><code>git reflog </code></pre> <p>Somewhere in this list is the commit that ... | 119 | git | <h1>How do I undo 'git reset'?</h1>
<p>How do I undo this command?</p>
<pre><code>git reset HEAD~
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,765 | git | # How do I undo 'git reset'?
How do I undo this command?
```
git reset HEAD~
``` | ### Short answer:
```
git reset 'HEAD@{1}'
```
### Long answer:
Git keeps a log of all ref updates (e.g., checkout, reset, commit, merge). You can view it by typing:
```
git reflog
```
Somewhere in this list is the commit that you lost. Let's say you just typed `git reset HEAD~` and want to undo it. My reflog look... |
1552340 | How to list only the names of files that changed between two commits | 2,803 | 2009-10-12 01:48:06 | <p>I have a bunch of commits in the repository. I want to see a list of files changed between two commits - from <em>SHA1</em> to <em>SHA2</em>.</p>
<p>What command should I use?</p>
| 1,330,112 | 58,743 | 2023-07-24 12:36:59 | 1,552,353 | 3,720 | 2009-10-12 01:51:34 | 157,237 | 2023-07-24 12:36:59 | https://stackoverflow.com/q/1552340 | https://stackoverflow.com/a/1552353 | <pre><code>git diff --name-only SHA1 SHA2
</code></pre>
<p>where you only need to include enough of the SHA hash to identify the commits. The order of the SHAs does not matter. The output (which includes the relative path, not just the file name) follows this format:</p>
<pre><code> dir 1/dir 2/filename.ext
dir 3/dir ... | <pre><code>git diff --name-only SHA1 SHA2 </code></pre> <p>where you only need to include enough of the SHA hash to identify the commits. The order of the SHAs does not matter. The output (which includes the relative path, not just the file name) follows this format:</p> <pre><code> dir 1/dir 2/filename.ext dir 3/dir ... | 119, 9033 | git, git-diff | <h1>How to list only the names of files that changed between two commits</h1>
<p>I have a bunch of commits in the repository. I want to see a list of files changed between two commits - from <em>SHA1</em> to <em>SHA2</em>.</p>
<p>What command should I use?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,766 | git | # How to list only the names of files that changed between two commits
I have a bunch of commits in the repository. I want to see a list of files changed between two commits - from *SHA1* to *SHA2*.
What command should I use? | ```
git diff --name-only SHA1 SHA2
```
where you only need to include enough of the SHA hash to identify the commits. The order of the SHAs does not matter. The output (which includes the relative path, not just the file name) follows this format:
```
dir 1/dir 2/filename.ext
dir 3/dir 4/other filename.ext
```
You... |
987142 | Make .gitignore ignore everything except a few files | 2,767 | 2009-06-12 15:04:49 | <p>I understand that a <code>.gitignore</code> file cloaks specified files from Git's version control.</p>
<p>How do I tell <code>.gitignore</code> to ignore everything except the files I'm tracking with Git? Something like:</p>
<pre class="lang-bash prettyprint-override"><code># Ignore everything:
*
# Do not ignore t... | 1,043,530 | 120,898 | 2025-02-08 17:05:50 | 987,162 | 3,676 | 2009-06-12 15:07:38 | 109,869 | 2024-05-21 14:54:49 | https://stackoverflow.com/q/987142 | https://stackoverflow.com/a/987162 | <blockquote>
<p>An optional prefix <code>!</code> which negates the pattern; any matching file excluded by
a previous pattern will become included again. If a negated pattern matches,
this will override lower precedence patterns sources.</p>
</blockquote>
<pre class="lang-bash prettyprint-override"><code># Ignore every... | <blockquote> <p>An optional prefix <code>!</code> which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.</p> </blockquote> <pre class="lang-bash prettyprint-override"><code># Ignore every... | 119, 25056 | git, gitignore | <h1>Make .gitignore ignore everything except a few files</h1>
<p>I understand that a <code>.gitignore</code> file cloaks specified files from Git's version control.</p>
<p>How do I tell <code>.gitignore</code> to ignore everything except the files I'm tracking with Git? Something like:</p>
<pre class="lang-bash prettyp... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,767 | git | # Make .gitignore ignore everything except a few files
I understand that a `.gitignore` file cloaks specified files from Git's version control.
How do I tell `.gitignore` to ignore everything except the files I'm tracking with Git? Something like:
```
# Ignore everything:
*
# Do not ignore these files:
script.pl
te... | > An optional prefix `!` which negates the pattern; any matching file excluded by
> a previous pattern will become included again. If a negated pattern matches,
> this will override lower precedence patterns sources.
```
# Ignore everything
*
# But not these files...
!.gitignore
!script.pl
!template.latex
# etc...
#... |
3040833 | How do I stash only one file out of multiple files that have changed? | 3,875 | 2010-06-14 20:52:33 | <p>How do I stash only one of the multiple changed files on my branch?</p>
| 1,370,882 | 164,299 | 2024-08-10 18:49:50 | 17,969,785 | 3,671 | 2013-07-31 11:59:56 | 549,315 | 2020-12-15 04:19:50 | https://stackoverflow.com/q/3040833 | https://stackoverflow.com/a/17969785 | <pre><code>git stash push -p -m "my commit message"
</code></pre>
<p><code>-p</code> let's you select the hunks that should be stashed; whole files can be selected as well.</p>
<p>You'll be prompted with a few actions for each hunk:</p>
<pre><code> y - stash this hunk
n - do not stash this hunk
q - qu... | <pre><code>git stash push -p -m "my commit message" </code></pre> <p><code>-p</code> let's you select the hunks that should be stashed; whole files can be selected as well.</p> <p>You'll be prompted with a few actions for each hunk:</p> <pre><code> y - stash this hunk n - do not stash this hunk q - qu... | 119, 13091 | git, git-stash | <h1>How do I stash only one file out of multiple files that have changed?</h1>
<p>How do I stash only one of the multiple changed files on my branch?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,768 | git | # How do I stash only one file out of multiple files that have changed?
How do I stash only one of the multiple changed files on my branch? | ```
git stash push -p -m "my commit message"
```
`-p` let's you select the hunks that should be stashed; whole files can be selected as well.
You'll be prompted with a few actions for each hunk:
```
y - stash this hunk
n - do not stash this hunk
q - quit; do not stash this hunk or any of the remaining ones
... |
2862590 | How to replace master branch in Git, entirely, from another branch? | 2,177 | 2010-05-19 03:06:29 | <p>I have two branches in my Git repository:</p>
<ol>
<li><code>master</code></li>
<li><code>seotweaks</code> (created originally from <code>master</code>)</li>
</ol>
<p>I created <code>seotweaks</code> with the intention of quickly merging it back into <code>master</code>. However, that was three months ago and the ... | 974,350 | 220,274 | 2024-10-03 05:59:34 | 2,862,938 | 3,649 | 2010-05-19 04:51:31 | 240,633 | 2024-10-03 05:59:34 | https://stackoverflow.com/q/2862590 | https://stackoverflow.com/a/2862938 | <p>You should be able to use the “ours” merge strategy to overwrite master with seotweaks like this:</p>
<pre><code>git checkout master
git pull
git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks
</code></pre>
<p>The first two steps are a useful precaution to ensure your local copy ... | <p>You should be able to use the “ours” merge strategy to overwrite master with seotweaks like this:</p> <pre><code>git checkout master git pull git checkout seotweaks git merge -s ours master git checkout master git merge seotweaks </code></pre> <p>The first two steps are a useful precaution to ensure your local copy ... | 119, 717, 76220 | git, git-branch, merge | <h1>How to replace master branch in Git, entirely, from another branch?</h1>
<p>I have two branches in my Git repository:</p>
<ol>
<li><code>master</code></li>
<li><code>seotweaks</code> (created originally from <code>master</code>)</li>
</ol>
<p>I created <code>seotweaks</code> with the intention of quickly merging ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,769 | git | # How to replace master branch in Git, entirely, from another branch?
I have two branches in my Git repository:
1. `master`
2. `seotweaks` (created originally from `master`)
I created `seotweaks` with the intention of quickly merging it back into `master`. However, that was three months ago and the code in this bran... | You should be able to use the “ours” merge strategy to overwrite master with seotweaks like this:
```
git checkout master
git pull
git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks
```
The first two steps are a useful precaution to ensure your local copy of master is up-to-date. ... |
1459150 | How to undo "git commit --amend" done instead of "git commit" | 2,044 | 2009-09-22 09:56:19 | <p>I accidentally amended my previous commit. The commit should have been separate to keep history of the changes I made to a particular file.</p>
<p>Is there a way to undo that last commit? If I do something like <code>git reset --hard HEAD^</code>, the first commit also is undone.</p>
<p>(I have not yet pushed to a... | 801,342 | 109,305 | 2023-10-19 21:46:40 | 1,459,264 | 3,619 | 2009-09-22 10:23:44 | 19,563 | 2022-07-15 22:36:16 | https://stackoverflow.com/q/1459150 | https://stackoverflow.com/a/1459264 | <p>What you need to do is to create a new commit with the same details as the current <code>HEAD</code> commit, but with the parent as the previous version of <code>HEAD</code>. <code>git reset --soft</code> will move the branch pointer so that the next commit happens on top of a different commit from where the current... | <p>What you need to do is to create a new commit with the same details as the current <code>HEAD</code> commit, but with the parent as the previous version of <code>HEAD</code>. <code>git reset --soft</code> will move the branch pointer so that the next commit happens on top of a different commit from where the current... | 119, 5597, 5766, 30968 | commit, git, git-amend, undo | <h1>How to undo "git commit --amend" done instead of "git commit"</h1>
<p>I accidentally amended my previous commit. The commit should have been separate to keep history of the changes I made to a particular file.</p>
<p>Is there a way to undo that last commit? If I do something like <code>git reset --hard HEAD^</code... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,770 | git | # How to undo "git commit --amend" done instead of "git commit"
I accidentally amended my previous commit. The commit should have been separate to keep history of the changes I made to a particular file.
Is there a way to undo that last commit? If I do something like `git reset --hard HEAD^`, the first commit also is... | What you need to do is to create a new commit with the same details as the current `HEAD` commit, but with the parent as the previous version of `HEAD`. `git reset --soft` will move the branch pointer so that the next commit happens on top of a different commit from where the current branch head is now.
```
# Move the... |
835501 | How do you stash an untracked file? | 2,512 | 2009-05-07 15:54:20 | <p>I have changes to a file, plus a new file, and would like to use git stash to put them away while I switch to another task. But git stash by itself stashes only the changes to the existing file; the new file remains in my working tree, cluttering up my future work. How do I stash this untracked file?</p>
| 1,274,746 | 18,103 | 2024-04-19 18:00:10 | 835,561 | 3,611 | 2009-05-07 16:02:50 | 53,850 | 2023-04-26 08:00:17 | https://stackoverflow.com/q/835501 | https://stackoverflow.com/a/835561 | <p>To stash your working directory including untracked files (especially those that are in the <code>.gitignore</code>) then you probably want to use this cmd:</p>
<pre class="lang-bash prettyprint-override"><code>git stash --include-untracked
</code></pre>
<p>Alternatively, you can use the shorthand <code>-u</code> in... | <p>To stash your working directory including untracked files (especially those that are in the <code>.gitignore</code>) then you probably want to use this cmd:</p> <pre class="lang-bash prettyprint-override"><code>git stash --include-untracked </code></pre> <p>Alternatively, you can use the shorthand <code>-u</code> in... | 119, 13091 | git, git-stash | <h1>How do you stash an untracked file?</h1>
<p>I have changes to a file, plus a new file, and would like to use git stash to put them away while I switch to another task. But git stash by itself stashes only the changes to the existing file; the new file remains in my working tree, cluttering up my future work. How ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,771 | git | # How do you stash an untracked file?
I have changes to a file, plus a new file, and would like to use git stash to put them away while I switch to another task. But git stash by itself stashes only the changes to the existing file; the new file remains in my working tree, cluttering up my future work. How do I stash ... | To stash your working directory including untracked files (especially those that are in the `.gitignore`) then you probably want to use this cmd:
```
git stash --include-untracked
```
Alternatively, you can use the shorthand `-u` instead of `--include-untracked`, or simply `git stash --all` (see warning below for thi... |
5506339 | How can I git stash a specific file? | 2,596 | 2011-03-31 21:05:38 | <p>How can I stash a specific file leaving the others currently modified out of the stash I am about to save?</p>
<p>For example, if git status gives me this:</p>
<pre><code>younker % git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged for commit:
# (use &... | 1,522,143 | 272,203 | 2025-04-14 21:09:30 | 5,506,483 | 3,567 | 2011-03-31 21:19:11 | 41,071 | 2025-01-05 10:45:43 | https://stackoverflow.com/q/5506339 | https://stackoverflow.com/a/5506483 | <p>Since git 2.13, there is a command to save a specific path to the stash: <code>git stash push <path></code>. For example:</p>
<pre><code>git stash push -m welcome_cart app/views/cart/welcome.thtml
</code></pre>
<hr />
<p>With earlier versions:</p>
<p>You can do that using <code>git stash --patch</code> (or <co... | <p>Since git 2.13, there is a command to save a specific path to the stash: <code>git stash push <path></code>. For example:</p> <pre><code>git stash push -m welcome_cart app/views/cart/welcome.thtml </code></pre> <hr /> <p>With earlier versions:</p> <p>You can do that using <code>git stash --patch</code> (or <co... | 119, 13091 | git, git-stash | <h1>How can I git stash a specific file?</h1>
<p>How can I stash a specific file leaving the others currently modified out of the stash I am about to save?</p>
<p>For example, if git status gives me this:</p>
<pre><code>younker % git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,773 | git | # How can I git stash a specific file?
How can I stash a specific file leaving the others currently modified out of the stash I am about to save?
For example, if git status gives me this:
```
younker % git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes not staged f... | Since git 2.13, there is a command to save a specific path to the stash: `git stash push <path>`. For example:
```
git stash push -m welcome_cart app/views/cart/welcome.thtml
```
---
With earlier versions:
You can do that using `git stash --patch` (or `git stash -p`) -- you'll enter interactive mode where you'll be... |
953481 | How do I find and restore a deleted file in a Git repository? | 3,251 | 2009-06-04 22:40:34 | <p>Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I discover that I need to restore that file after deleting it.</p>
<p>I know I can checkout a file using <code>git checkout <commit> -- filename.txt</code>, but I don't know when that file ... | 1,178,267 | 56,430 | 2024-01-29 11:56:27 | 1,113,140 | 3,563 | 2009-07-11 07:12:20 | 19,563 | 2024-01-29 11:53:22 | https://stackoverflow.com/q/953481 | https://stackoverflow.com/a/1113140 | <p>Find the last commit that affected the given path. As the file isn't in the HEAD commit, that previous commit must have deleted it.</p>
<pre class="lang-bash prettyprint-override"><code>git rev-list -n 1 HEAD -- <file_path>
</code></pre>
<p>Then checkout the version at the commit before, using the caret (<cod... | <p>Find the last commit that affected the given path. As the file isn't in the HEAD commit, that previous commit must have deleted it.</p> <pre class="lang-bash prettyprint-override"><code>git rev-list -n 1 HEAD -- <file_path> </code></pre> <p>Then checkout the version at the commit before, using the caret (<cod... | 119, 724, 37230 | file-io, git, git-checkout | <h1>How do I find and restore a deleted file in a Git repository?</h1>
<p>Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I discover that I need to restore that file after deleting it.</p>
<p>I know I can checkout a file using <code>git checkout ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,774 | git | # How do I find and restore a deleted file in a Git repository?
Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I discover that I need to restore that file after deleting it.
I know I can checkout a file using `git checkout <commit> -- filename... | Find the last commit that affected the given path. As the file isn't in the HEAD commit, that previous commit must have deleted it.
```
git rev-list -n 1 HEAD -- <file_path>
```
Then checkout the version at the commit before, using the caret (`^`) symbol:
```
git checkout <deleting_commit>^ -- <file_path>
```
Or in... |
107701 | How can I Remove .DS_Store files from a Git repository? | 1,838 | 2008-09-20 09:15:50 | <p>How can I remove those annoying Mac OS X <code>.DS_Store</code> files from a Git repository?</p>
| 1,237,893 | 1,450 | 2023-08-21 05:24:12 | 107,921 | 3,531 | 2008-09-20 11:18:06 | 10,947 | 2022-08-10 10:13:57 | https://stackoverflow.com/q/107701 | https://stackoverflow.com/a/107921 | <p>Remove existing <code>.DS_Store</code> files from the repository:</p>
<pre><code>find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
</code></pre>
<p>Add this line:</p>
<pre><code>.DS_Store
</code></pre>
<p>to the file <code>.gitignore</code>, which can be found at the top level of your repository (... | <p>Remove existing <code>.DS_Store</code> files from the repository:</p> <pre><code>find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch </code></pre> <p>Add this line:</p> <pre><code>.DS_Store </code></pre> <p>to the file <code>.gitignore</code>, which can be found at the top level of your repository (... | 119, 369, 25056 | git, gitignore, macos | <h1>How can I Remove .DS_Store files from a Git repository?</h1>
<p>How can I remove those annoying Mac OS X <code>.DS_Store</code> files from a Git repository?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,775 | git | # How can I Remove .DS_Store files from a Git repository?
How can I remove those annoying Mac OS X `.DS_Store` files from a Git repository? | Remove existing `.DS_Store` files from the repository:
```
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
```
Add this line:
```
.DS_Store
```
to the file `.gitignore`, which can be found at the top level of your repository (or create the file if it isn't there already). You can do this easily... |
161813 | How do I resolve merge conflicts in a Git repository? | 5,438 | 2008-10-02 11:31:05 | <p>How do I resolve merge conflicts in my Git repository?</p>
| 3,784,530 | 3,713 | 2025-03-21 15:41:54 | 163,659 | 3,453 | 2008-10-02 17:50:25 | 101 | 2022-10-13 17:59:50 | https://stackoverflow.com/q/161813 | https://stackoverflow.com/a/163659 | <p>Try:</p>
<pre class="lang-bash prettyprint-override"><code>git mergetool
</code></pre>
<p>It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing ... | <p>Try:</p> <pre class="lang-bash prettyprint-override"><code>git mergetool </code></pre> <p>It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing ... | 119, 28897, 62599, 106113 | git, git-merge, git-merge-conflict, merge-conflict-resolution | <h1>How do I resolve merge conflicts in a Git repository?</h1>
<p>How do I resolve merge conflicts in my Git repository?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,776 | git | # How do I resolve merge conflicts in a Git repository?
How do I resolve merge conflicts in my Git repository? | Try:
```
git mergetool
```
It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing by hand certainly.
---
As per [Josh Glover's comment](https://st... |
15772134 | Can I delete (or undo) a git commit but keep the changes? | 2,240 | 2013-04-02 18:56:15 | <p>In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features. But just using a "git checkout master" preserved the changes I also made in my development branch, thus breaking some ... | 1,595,113 | 1,117,004 | 2025-05-23 10:54:29 | 15,772,171 | 3,373 | 2013-04-02 18:58:39 | 31,582 | 2021-11-15 09:27:19 | https://stackoverflow.com/q/15772134 | https://stackoverflow.com/a/15772171 | <p>It's as simple as this:</p>
<pre><code>git reset HEAD^
</code></pre>
<p>Note: some shells treat <code>^</code> as a special character (for example some Windows shells or <a href="http://bewatermyfriend.org/p/2016/002/" rel="noreferrer">ZSH with globbing enabled</a>), so you may have to quote <code>"HEAD^"<... | <p>It's as simple as this:</p> <pre><code>git reset HEAD^ </code></pre> <p>Note: some shells treat <code>^</code> as a special character (for example some Windows shells or <a href="http://bewatermyfriend.org/p/2016/002/" rel="noreferrer">ZSH with globbing enabled</a>), so you may have to quote <code>"HEAD^"<... | 119, 5766, 51381 | git, git-reset, undo | <h1>Can I delete (or undo) a git commit but keep the changes?</h1>
<p>In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features. But just using a "git checkout master" preserved th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,777 | git | # Can I delete (or undo) a git commit but keep the changes?
In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features. But just using a "git checkout master" preserved the changes... | It's as simple as this:
```
git reset HEAD^
```
Note: some shells treat `^` as a special character (for example some Windows shells or [ZSH with globbing enabled](http://bewatermyfriend.org/p/2016/002/)), so you may have to quote `"HEAD^"` or use `HEAD~1` in those cases.
`git reset` without a `--hard` or `--soft` mo... |
5509543 | How do I properly force a Git push? | 1,921 | 2011-04-01 05:35:54 | <p>I've set up a remote non-bare "main" repo and cloned it to my computer. I made some local changes, updated my local repository, and pushed the changes back to my remote repo. Things were fine up to that point.</p>
<p>Now, I had to change something in the remote repo. Then I changed something in my local repo. I rea... | 2,950,289 | 1,580,201 | 2024-05-15 13:39:43 | 12,610,763 | 3,315 | 2012-09-26 21:31:33 | 1,696,153 | 2017-06-21 13:19:08 | https://stackoverflow.com/q/5509543 | https://stackoverflow.com/a/12610763 | <p>Just do:</p>
<pre><code>git push origin <your_branch_name> --force
</code></pre>
<p>or if you have a specific repo:</p>
<pre><code>git push https://git.... --force
</code></pre>
<p>This will delete your previous commit(s) and push your current one.</p>
<p>It may not be proper, but if anyone stumbles upon ... | <p>Just do:</p> <pre><code>git push origin <your_branch_name> --force </code></pre> <p>or if you have a specific repo:</p> <pre><code>git push https://git.... --force </code></pre> <p>This will delete your previous commit(s) and push your current one.</p> <p>It may not be proper, but if anyone stumbles upon ... | 119, 4236, 28898, 106074 | git, git-non-bare-repository, git-push, push | <h1>How do I properly force a Git push?</h1>
<p>I've set up a remote non-bare "main" repo and cloned it to my computer. I made some local changes, updated my local repository, and pushed the changes back to my remote repo. Things were fine up to that point.</p>
<p>Now, I had to change something in the remote repo. The... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,778 | git | # How do I properly force a Git push?
I've set up a remote non-bare "main" repo and cloned it to my computer. I made some local changes, updated my local repository, and pushed the changes back to my remote repo. Things were fine up to that point.
Now, I had to change something in the remote repo. Then I changed some... | Just do:
```
git push origin <your_branch_name> --force
```
or if you have a specific repo:
```
git push https://git.... --force
```
This will delete your previous commit(s) and push your current one.
It may not be proper, but if anyone stumbles upon this page, thought they might want a simple solution...
### Sho... |
7147270 | Hard reset of a single file | 1,907 | 2011-08-22 12:12:52 | <p>How do I discard the changes to a single file and overwrite it with a fresh HEAD copy? I want to do <code>git reset --hard</code> to only a single file.</p>
| 1,651,955 | 62,811 | 2024-08-12 08:06:59 | 7,147,320 | 3,254 | 2011-08-22 12:16:21 | 223,092 | 2022-07-25 04:00:21 | https://stackoverflow.com/q/7147270 | https://stackoverflow.com/a/7147320 | <p>To reset both the working copy of <code>my-file.txt</code> and its state in the Git index to that of HEAD:</p>
<pre><code>git checkout HEAD -- my-file.txt
</code></pre>
<p><code>--</code> means <em>"treat every argument after this point as a filename"</em>. More details in <a href="https://stackoverflow.co... | <p>To reset both the working copy of <code>my-file.txt</code> and its state in the Git index to that of HEAD:</p> <pre><code>git checkout HEAD -- my-file.txt </code></pre> <p><code>--</code> means <em>"treat every argument after this point as a filename"</em>. More details in <a href="https://stackoverflow.co... | 119 | git | <h1>Hard reset of a single file</h1>
<p>How do I discard the changes to a single file and overwrite it with a fresh HEAD copy? I want to do <code>git reset --hard</code> to only a single file.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,779 | git | # Hard reset of a single file
How do I discard the changes to a single file and overwrite it with a fresh HEAD copy? I want to do `git reset --hard` to only a single file. | To reset both the working copy of `my-file.txt` and its state in the Git index to that of HEAD:
```
git checkout HEAD -- my-file.txt
```
`--` means *"treat every argument after this point as a filename"*. More details in [this answer](https://stackoverflow.com/questions/6561142/different-between-git-checkout-filename... |
1587846 | How do I show the changes which have been staged? | 2,685 | 2009-10-19 09:57:27 | <p>I staged a few changes to be committed. How do I see the diffs of all files which are staged for the next commit? Is there a handy one-liner for this?</p>
<p><a href="http://git-scm.com/docs/git-status" rel="noreferrer"><code>git status</code></a> only shows names of files which are staged, but I want to see the act... | 1,239,189 | 91,757 | 2024-08-04 13:50:50 | 1,587,877 | 3,239 | 2009-10-19 10:07:10 | 19,563 | 2018-02-28 23:35:53 | https://stackoverflow.com/q/1587846 | https://stackoverflow.com/a/1587877 | <p>It should just be:</p>
<pre><code>git diff --cached
</code></pre>
<p><code>--cached</code> means show the changes in the cache/index (i.e. staged changes) against the current <code>HEAD</code>. <code>--staged</code> is a synonym for <code>--cached</code>.</p>
<p><code>--staged</code> and <code>--cached</code> doe... | <p>It should just be:</p> <pre><code>git diff --cached </code></pre> <p><code>--cached</code> means show the changes in the cache/index (i.e. staged changes) against the current <code>HEAD</code>. <code>--staged</code> is a synonym for <code>--cached</code>.</p> <p><code>--staged</code> and <code>--cached</code> doe... | 119, 606, 3346, 9033, 74978 | diff, dvcs, git, git-diff, git-stage | <h1>How do I show the changes which have been staged?</h1>
<p>I staged a few changes to be committed. How do I see the diffs of all files which are staged for the next commit? Is there a handy one-liner for this?</p>
<p><a href="http://git-scm.com/docs/git-status" rel="noreferrer"><code>git status</code></a> only shows... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,780 | git | # How do I show the changes which have been staged?
I staged a few changes to be committed. How do I see the diffs of all files which are staged for the next commit? Is there a handy one-liner for this?
[`git status`](http://git-scm.com/docs/git-status) only shows names of files which are staged, but I want to see th... | It should just be:
```
git diff --cached
```
`--cached` means show the changes in the cache/index (i.e. staged changes) against the current `HEAD`. `--staged` is a synonym for `--cached`.
`--staged` and `--cached` does not point to `HEAD`, just difference with respect to `HEAD`. If you cherry pick what to commit usi... |
10312521 | How do I fetch all Git branches? | 2,430 | 2012-04-25 09:05:26 | <p>I cloned a Git repository containing many branches. However, <code>git branch</code> only shows one:</p>
<pre><code>$ git branch
* master
</code></pre>
<p>How would I pull all the branches locally so when I do <code>git branch</code>, it shows the following?</p>
<pre><code>$ git branch
* master
* staging
* etc...
</... | 3,157,068 | 651,174 | 2025-04-12 07:14:47 | 10,312,587 | 3,206 | 2012-04-25 09:10:23 | 979,987 | 2024-06-26 23:59:40 | https://stackoverflow.com/q/10312521 | https://stackoverflow.com/a/10312587 | <h3>TL;DR answer</h3>
<pre class="lang-bash prettyprint-override"><code>git branch -r \
| grep -v '\->' \
| sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" \
| while read remote; do \
git branch --track "${remote#origin/}" "$remote"; \
done
git fetch --all
git pull --all
</code></pre>
... | <h3>TL;DR answer</h3> <pre class="lang-bash prettyprint-override"><code>git branch -r \ | grep -v '\->' \ | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" \ | while read remote; do \ git branch --track "${remote#origin/}" "$remote"; \ done git fetch --all git pull --all </code></pre> ... | 119, 1879, 76220 | branch, git, git-branch | <h1>How do I fetch all Git branches?</h1>
<p>I cloned a Git repository containing many branches. However, <code>git branch</code> only shows one:</p>
<pre><code>$ git branch
* master
</code></pre>
<p>How would I pull all the branches locally so when I do <code>git branch</code>, it shows the following?</p>
<pre><code>$... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,781 | git | # How do I fetch all Git branches?
I cloned a Git repository containing many branches. However, `git branch` only shows one:
```
$ git branch
* master
```
How would I pull all the branches locally so when I do `git branch`, it shows the following?
```
$ git branch
* master
* staging
* etc...
``` | ### TL;DR answer
```
git branch -r \
| grep -v '\->' \
| sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" \
| while read remote; do \
git branch --track "${remote#origin/}" "$remote"; \
done
git fetch --all
git pull --all
```
*(`grep -v` matches the inverse of given string; `sed` removes control sequences: `\x1B` mat... |
6313126 | How do I remove a directory from a Git repository? | 1,732 | 2011-06-10 23:54:53 | <p>How can I delete a single directory containing files from a Git repository?</p>
| 2,186,747 | 274,117 | 2022-11-22 07:46:54 | 6,313,301 | 3,184 | 2011-06-11 00:37:36 | 720,030 | 2022-09-06 16:59:21 | https://stackoverflow.com/q/6313126 | https://stackoverflow.com/a/6313301 | <h4>Remove directory from Git and local</h4>
<p>Checkout 'master' with both directories:</p>
<pre><code>git rm -r one-of-the-directories // This deletes from filesystem
git commit . -m "Remove duplicated directory"
git push origin <your-git-branch> (typically 'master', but not always)
</code></pre>
<h4>... | <h4>Remove directory from Git and local</h4> <p>Checkout 'master' with both directories:</p> <pre><code>git rm -r one-of-the-directories // This deletes from filesystem git commit . -m "Remove duplicated directory" git push origin <your-git-branch> (typically 'master', but not always) </code></pre> <h4>... | 119, 37510 | delete-file, git | <h1>How do I remove a directory from a Git repository?</h1>
<p>How can I delete a single directory containing files from a Git repository?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,782 | git | # How do I remove a directory from a Git repository?
How can I delete a single directory containing files from a Git repository? | #### Remove directory from Git and local
Checkout 'master' with both directories:
```
git rm -r one-of-the-directories // This deletes from filesystem
git commit . -m "Remove duplicated directory"
git push origin <your-git-branch> (typically 'master', but not always)
```
#### Remove directory from Git but NOT local
... |
52704 | How do I discard unstaged changes in Git? | 6,472 | 2008-09-09 19:33:59 | <p>How do I discard changes in my working copy that are not in the index?</p>
| 4,600,305 | 4,883 | 2025-08-21 06:43:57 | 52,719 | 3,171 | 2008-09-09 19:39:24 | 893 | 2018-09-11 00:14:38 | https://stackoverflow.com/q/52704 | https://stackoverflow.com/a/52719 | <p>Another quicker way is:</p>
<pre><code>git stash save --keep-index --include-untracked
</code></pre>
<p>You don't need to include <code>--include-untracked</code> if you don't want to be thorough about it.</p>
<p>After that, you can drop that stash with a <code>git stash drop</code> command if you like.</p>
| <p>Another quicker way is:</p> <pre><code>git stash save --keep-index --include-untracked </code></pre> <p>You don't need to include <code>--include-untracked</code> if you don't want to be thorough about it.</p> <p>After that, you can drop that stash with a <code>git stash drop</code> command if you like.</p> | 119, 456, 165501 | git, git-restore, version-control | <h1>How do I discard unstaged changes in Git?</h1>
<p>How do I discard changes in my working copy that are not in the index?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,783 | git | # How do I discard unstaged changes in Git?
How do I discard changes in my working copy that are not in the index? | Another quicker way is:
```
git stash save --keep-index --include-untracked
```
You don't need to include `--include-untracked` if you don't want to be thorough about it.
After that, you can drop that stash with a `git stash drop` command if you like. |
30590083 | git: how to rename a branch (both local and remote)? | 1,968 | 2015-06-02 07:36:30 | <p>I have a local branch <code>master</code> that points to a remote branch <code>origin/regacy</code> (oops, typo!).</p>
<p>How do I rename the remote branch to <code>origin/legacy</code> or <code>origin/master</code>?</p>
<p>I tried:</p>
<pre><code>git remote rename regacy legacy
</code></pre>
<p>But this gave an err... | 1,706,771 | 4,609,541 | 2025-08-13 08:28:13 | 30,590,238 | 3,155 | 2015-06-02 07:44:38 | 1,755,598 | 2024-07-01 01:18:06 | https://stackoverflow.com/q/30590083 | https://stackoverflow.com/a/30590238 | <p><a href="https://i.sstatic.net/YeBYR.jpg" rel="noreferrer"><img src="https://i.sstatic.net/YeBYR.jpg" alt="schematic, cute git remote graph" /></a></p>
<hr />
<p>There are a few ways to accomplish that:</p>
<ol>
<li>Change your local branch and then push your changes</li>
<li>Push the branch to remote with the new n... | <p><a href="https://i.sstatic.net/YeBYR.jpg" rel="noreferrer"><img src="https://i.sstatic.net/YeBYR.jpg" alt="schematic, cute git remote graph" /></a></p> <hr /> <p>There are a few ways to accomplish that:</p> <ol> <li>Change your local branch and then push your changes</li> <li>Push the branch to remote with the new n... | 119, 4510, 7330, 76220 | git, git-branch, rename, repository | <h1>git: how to rename a branch (both local and remote)?</h1>
<p>I have a local branch <code>master</code> that points to a remote branch <code>origin/regacy</code> (oops, typo!).</p>
<p>How do I rename the remote branch to <code>origin/legacy</code> or <code>origin/master</code>?</p>
<p>I tried:</p>
<pre><code>git rem... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,784 | git | # git: how to rename a branch (both local and remote)?
I have a local branch `master` that points to a remote branch `origin/regacy` (oops, typo!).
How do I rename the remote branch to `origin/legacy` or `origin/master`?
I tried:
```
git remote rename regacy legacy
```
But this gave an error:
> error : Could not ... | [](https://i.sstatic.net/YeBYR.jpg)
---
There are a few ways to accomplish that:
1. Change your local branch and then push your changes
2. Push the branch to remote with the new name while keeping the original name locally
### Renaming local and re... |
10228760 | How do I fix a Git detached head? | 2,199 | 2012-04-19 13:07:05 | <p>I was doing some work in my repository and noticed a file had local changes. I didn't want them anymore so I deleted the file, thinking I can just checkout a fresh copy. I wanted to do the Git equivalent of</p>
<pre><code>svn up .
</code></pre>
<p>Using <code>git pull</code> didn't seem to work. Some random search... | 2,821,869 | 20,426 | 2025-07-07 23:21:25 | 10,229,202 | 3,142 | 2012-04-19 13:32:58 | 106,205 | 2024-07-08 13:15:20 | https://stackoverflow.com/q/10228760 | https://stackoverflow.com/a/10229202 | <p>Detached head means you are no longer on a branch, you have checked out a single commit in the history (in this case the commit previous to HEAD, i.e. HEAD^).</p>
<h2>If you want to <em>keep</em> your changes associated with the detached HEAD</h2>
<ol>
<li>Run <code>git branch tmp</code> - this will save your change... | <p>Detached head means you are no longer on a branch, you have checked out a single commit in the history (in this case the commit previous to HEAD, i.e. HEAD^).</p> <h2>If you want to <em>keep</em> your changes associated with the detached HEAD</h2> <ol> <li>Run <code>git branch tmp</code> - this will save your change... | 119, 98582 | git, git-detached-head | <h1>How do I fix a Git detached head?</h1>
<p>I was doing some work in my repository and noticed a file had local changes. I didn't want them anymore so I deleted the file, thinking I can just checkout a fresh copy. I wanted to do the Git equivalent of</p>
<pre><code>svn up .
</code></pre>
<p>Using <code>git pull</co... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,785 | git | # How do I fix a Git detached head?
I was doing some work in my repository and noticed a file had local changes. I didn't want them anymore so I deleted the file, thinking I can just checkout a fresh copy. I wanted to do the Git equivalent of
```
svn up .
```
Using `git pull` didn't seem to work. Some random searchi... | Detached head means you are no longer on a branch, you have checked out a single commit in the history (in this case the commit previous to HEAD, i.e. HEAD^).
## If you want to *keep* your changes associated with the detached HEAD
1. Run `git branch tmp` - this will save your changes in a new branch called `tmp`.
2. ... |
11646107 | You have not concluded your merge (MERGE_HEAD exists) | 1,806 | 2012-07-25 08:58:17 | <p>I made a branch called 'f' and did a checkout to master. When I tried the <code>git pull</code> command I got this message:</p>
<pre><code>You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.
</code></pre>
<p>When I try the <code>git status</code>, it gave me the... | 2,136,588 | 1,429,990 | 2024-04-16 10:14:43 | 11,647,899 | 3,136 | 2012-07-25 10:38:31 | 1,365,319 | 2023-08-21 17:54:30 | https://stackoverflow.com/q/11646107 | https://stackoverflow.com/a/11647899 | <p>The problem is your previous pull failed to merge automatically and went to conflict state. And the conflict wasn't resolved properly before the next pull.</p>
<ol>
<li><p>Undo the merge and pull again.</p>
<p>To undo a merge:</p>
<p><code>git merge --abort</code> [Since git version 1.7.4]</p>
<p><code>git reset --... | <p>The problem is your previous pull failed to merge automatically and went to conflict state. And the conflict wasn't resolved properly before the next pull.</p> <ol> <li><p>Undo the merge and pull again.</p> <p>To undo a merge:</p> <p><code>git merge --abort</code> [Since git version 1.7.4]</p> <p><code>git reset --... | 119 | git | <h1>You have not concluded your merge (MERGE_HEAD exists)</h1>
<p>I made a branch called 'f' and did a checkout to master. When I tried the <code>git pull</code> command I got this message:</p>
<pre><code>You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.
</code></... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,786 | git | # You have not concluded your merge (MERGE_HEAD exists)
I made a branch called 'f' and did a checkout to master. When I tried the `git pull` command I got this message:
```
You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.
```
When I try the `git status`, it gav... | The problem is your previous pull failed to merge automatically and went to conflict state. And the conflict wasn't resolved properly before the next pull.
1. Undo the merge and pull again.
To undo a merge:
`git merge --abort` [Since git version 1.7.4]
`git reset --merge` [prior git versions]
2. Resolve th... |
5189560 | How do I squash my last N commits together? | 5,812 | 2011-03-04 04:11:26 | <p>How do I squash my last N commits together into one commit?</p>
| 4,740,594 | 97,101 | 2025-09-27 10:20:10 | 5,189,600 | 3,126 | 2011-03-04 04:18:49 | 634,419 | 2025-09-05 07:32:50 | https://stackoverflow.com/q/5189560 | https://stackoverflow.com/a/5189600 | <p>Use <code>git rebase -i <after-this-commit></code> and replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in <a href="https://git-scm.com/docs/git-rebase#_interactive_mode" rel="noreferrer">the manual</a>:</p>
<ul>
<li><p>"fixup" t... | <p>Use <code>git rebase -i <after-this-commit></code> and replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in <a href="https://git-scm.com/docs/git-rebase#_interactive_mode" rel="noreferrer">the manual</a>:</p> <ul> <li><p>"fixup" t... | 119, 8974, 42532, 98455 | git, git-squash, rebase, squash | <h1>How do I squash my last N commits together?</h1>
<p>How do I squash my last N commits together into one commit?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,787 | git | # How do I squash my last N commits together?
How do I squash my last N commits together into one commit? | Use `git rebase -i <after-this-commit>` and replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in [the manual](https://git-scm.com/docs/git-rebase#_interactive_mode):
- "fixup" to discard the commit message, and squash it right away.
- "squash" to combine the commit message with... |
4099742 | How to compare files from two different branches | 2,296 | 2010-11-04 18:04:25 | <p>I have a script that works fine in one branch and is broken in another. I want to look at the two versions side-by-side and see what's different. Is there a way to do this?</p>
<p><strong>To be clear</strong> I'm not looking for a compare tool (I use <a href="https://en.wikipedia.org/wiki/Beyond_Compare" rel="norefe... | 1,480,297 | 17,744 | 2023-04-18 15:48:25 | 4,099,805 | 3,104 | 2010-11-04 18:13:11 | 54,249 | 2023-04-18 15:48:25 | https://stackoverflow.com/q/4099742 | https://stackoverflow.com/a/4099805 | <p><code>git diff</code> can show you the difference between two commits:</p>
<pre><code>git diff mybranch master -- myfile.cs
</code></pre>
<p>Or, equivalently:</p>
<pre><code>git diff mybranch..master -- myfile.cs
</code></pre>
<p>Note you must specify the relative path to the file. So if the file were in the src dir... | <p><code>git diff</code> can show you the difference between two commits:</p> <pre><code>git diff mybranch master -- myfile.cs </code></pre> <p>Or, equivalently:</p> <pre><code>git diff mybranch..master -- myfile.cs </code></pre> <p>Note you must specify the relative path to the file. So if the file were in the src dir... | 119, 9033 | git, git-diff | <h1>How to compare files from two different branches</h1>
<p>I have a script that works fine in one branch and is broken in another. I want to look at the two versions side-by-side and see what's different. Is there a way to do this?</p>
<p><strong>To be clear</strong> I'm not looking for a compare tool (I use <a href=... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,788 | git | # How to compare files from two different branches
I have a script that works fine in one branch and is broken in another. I want to look at the two versions side-by-side and see what's different. Is there a way to do this?
**To be clear** I'm not looking for a compare tool (I use [Beyond Compare](https://en.wikipedi... | `git diff` can show you the difference between two commits:
```
git diff mybranch master -- myfile.cs
```
Or, equivalently:
```
git diff mybranch..master -- myfile.cs
```
Note you must specify the relative path to the file. So if the file were in the src directory, you'd say `src/myfile.cs` instead of `myfile.cs`.
... |
791959 | Download a specific tag with Git | 2,153 | 2009-04-27 01:15:12 | <p>I'm trying to figure out how I can download a particular tag of a Git repository - it's one version behind the current version.</p>
<p>I saw there was a tag for the previous version on the git web page, with object name of something long hex number. </p>
<p>But the version name is "<code>Tagged release 1.1.5</code... | 1,726,461 | 64,895 | 2021-09-03 03:47:18 | 792,027 | 3,096 | 2009-04-27 01:53:48 | 289,651 | 2017-10-25 11:19:45 | https://stackoverflow.com/q/791959 | https://stackoverflow.com/a/792027 | <pre class="lang-bash prettyprint-override"><code>$ git clone
</code></pre>
<p>will give you the whole repository.</p>
<p>After the clone, you can list the tags with <code>$ git tag -l</code> and then checkout a specific tag:</p>
<pre class="lang-bash prettyprint-override"><code>$ git checkout tags/<tag_name>
... | <pre class="lang-bash prettyprint-override"><code>$ git clone </code></pre> <p>will give you the whole repository.</p> <p>After the clone, you can list the tags with <code>$ git tag -l</code> and then checkout a specific tag:</p> <pre class="lang-bash prettyprint-override"><code>$ git checkout tags/<tag_name> ... | 119, 34099, 60718 | git, git-clone, git-tag | <h1>Download a specific tag with Git</h1>
<p>I'm trying to figure out how I can download a particular tag of a Git repository - it's one version behind the current version.</p>
<p>I saw there was a tag for the previous version on the git web page, with object name of something long hex number. </p>
<p>But the version... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,789 | git | # Download a specific tag with Git
I'm trying to figure out how I can download a particular tag of a Git repository - it's one version behind the current version.
I saw there was a tag for the previous version on the git web page, with object name of something long hex number.
But the version name is "`Tagged releas... | ```
$ git clone
```
will give you the whole repository.
After the clone, you can list the tags with `$ git tag -l` and then checkout a specific tag:
```
$ git checkout tags/<tag_name>
```
Even better, checkout and create a branch (otherwise you will be on a branch named after the revision number of tag):
```
$ git... |
3640764 | Can I recover a branch after its deletion in Git? | 1,709 | 2010-09-04 03:25:19 | <p>If I run <code>git branch -d XYZ</code>, is there a way to recover the branch? Is there a way to go back as if I didn't run the delete branch command?</p>
| 816,252 | 260,127 | 2025-09-18 04:58:31 | 3,640,806 | 3,082 | 2010-09-04 03:43:13 | 203,773 | 2021-02-16 14:58:47 | https://stackoverflow.com/q/3640764 | https://stackoverflow.com/a/3640806 | <p>Yes, you should be able to do <code>git reflog --no-abbrev</code> and find the SHA1 for the commit at the tip of your deleted branch, then just <code>git checkout [sha]</code>. And once you're at that commit, you can just <code>git checkout -b [branchname]</code> to recreate the branch from there.</p>
<hr />
<p><str... | <p>Yes, you should be able to do <code>git reflog --no-abbrev</code> and find the SHA1 for the commit at the tip of your deleted branch, then just <code>git checkout [sha]</code>. And once you're at that commit, you can just <code>git checkout -b [branchname]</code> to recreate the branch from there.</p> <hr /> <p><str... | 119, 1879, 76220 | branch, git, git-branch | <h1>Can I recover a branch after its deletion in Git?</h1>
<p>If I run <code>git branch -d XYZ</code>, is there a way to recover the branch? Is there a way to go back as if I didn't run the delete branch command?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,790 | git | # Can I recover a branch after its deletion in Git?
If I run `git branch -d XYZ`, is there a way to recover the branch? Is there a way to go back as if I didn't run the delete branch command? | Yes, you should be able to do `git reflog --no-abbrev` and find the SHA1 for the commit at the tip of your deleted branch, then just `git checkout [sha]`. And once you're at that commit, you can just `git checkout -b [branchname]` to recreate the branch from there.
---
**Credit to @Cascabel for this condensed/one-lin... |
16330404 | How to remove remote origin from a Git repository | 1,644 | 2013-05-02 04:37:18 | <p>I just did <code>git init</code> to initialize my folder as Git repository and then added a remote repository using <code>git remote add origin URL</code>. Now I want to remove this <code>git remote add origin</code> and add a new repository <code>git remote add origin new-URL</code>. How can I do it?</p>
| 1,991,759 | 1,136,062 | 2024-12-26 11:48:50 | 16,330,439 | 3,047 | 2013-05-02 04:40:20 | 1,881,136 | 2020-01-28 11:06:53 | https://stackoverflow.com/q/16330404 | https://stackoverflow.com/a/16330439 | <p>Instead of removing and re-adding, you can do this:</p>
<pre><code>git remote set-url origin git://new.url.here
</code></pre>
<p>See this question: <a href="https://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git">How to change the URI (URL) for a remote Git repository?</a></p>
... | <p>Instead of removing and re-adding, you can do this:</p> <pre><code>git remote set-url origin git://new.url.here </code></pre> <p>See this question: <a href="https://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git">How to change the URI (URL) for a remote Git repository?</a></p> ... | 119, 41346 | git, git-remote | <h1>How to remove remote origin from a Git repository</h1>
<p>I just did <code>git init</code> to initialize my folder as Git repository and then added a remote repository using <code>git remote add origin URL</code>. Now I want to remove this <code>git remote add origin</code> and add a new repository <code>git remote... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,791 | git | # How to remove remote origin from a Git repository
I just did `git init` to initialize my folder as Git repository and then added a remote repository using `git remote add origin URL`. Now I want to remove this `git remote add origin` and add a new repository `git remote add origin new-URL`. How can I do it? | Instead of removing and re-adding, you can do this:
```
git remote set-url origin git://new.url.here
```
See this question: [How to change the URI (URL) for a remote Git repository?](https://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git)
To remove remote use this:
```
git remot... |
5308816 | How can I merge multiple commits onto another branch as a single squashed commit? | 1,959 | 2011-03-15 07:47:44 | <p>I have a remote Git server, here is the scenario which I want to perform:</p>
<ul>
<li><p>For each bug/feature I create a different Git branch</p></li>
<li><p>I keep on committing my code in that Git branch with un-official Git messages</p></li>
<li><p>In top repository we have to do one commit for one bug with off... | 1,247,322 | 148,869 | 2022-12-24 01:57:40 | 5,309,051 | 3,045 | 2011-03-15 08:16:45 | 573 | 2020-07-22 17:23:58 | https://stackoverflow.com/q/5308816 | https://stackoverflow.com/a/5309051 | <p>Say your bug fix branch is called <code>bugfix</code> and you want to merge it into <code>master</code>:</p>
<pre><code>git checkout master
git merge --squash bugfix
git commit
</code></pre>
<p>This will take all the commits from the <code>bugfix</code> branch, squash them into 1 commit, and merge it with your <code... | <p>Say your bug fix branch is called <code>bugfix</code> and you want to merge it into <code>master</code>:</p> <pre><code>git checkout master git merge --squash bugfix git commit </code></pre> <p>This will take all the commits from the <code>bugfix</code> branch, squash them into 1 commit, and merge it with your <code... | 119, 28897, 98455 | git, git-merge, git-squash | <h1>How can I merge multiple commits onto another branch as a single squashed commit?</h1>
<p>I have a remote Git server, here is the scenario which I want to perform:</p>
<ul>
<li><p>For each bug/feature I create a different Git branch</p></li>
<li><p>I keep on committing my code in that Git branch with un-official G... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,792 | git | # How can I merge multiple commits onto another branch as a single squashed commit?
I have a remote Git server, here is the scenario which I want to perform:
- For each bug/feature I create a different Git branch
- I keep on committing my code in that Git branch with un-official Git messages
- In top repository we ha... | Say your bug fix branch is called `bugfix` and you want to merge it into `master`:
```
git checkout master
git merge --squash bugfix
git commit
```
This will take all the commits from the `bugfix` branch, squash them into 1 commit, and merge it with your `master` branch.
---
**Explanation**:
```
git checkout maste... |
3197413 | How do I delete unpushed git commits? | 1,592 | 2010-07-07 17:47:23 | <p>I accidentally committed to the wrong branch.
How do I delete that commit?</p>
| 1,501,461 | 356,849 | 2021-11-29 13:20:59 | 3,197,432 | 3,044 | 2010-07-07 17:50:19 | 181,412 | 2016-10-03 11:44:20 | https://stackoverflow.com/q/3197413 | https://stackoverflow.com/a/3197432 | <p>Delete the most recent commit, keeping the work you've done:</p>
<pre><code>git reset --soft HEAD~1
</code></pre>
<p>Delete the most recent commit, <strong>destroying the work</strong> you've done:</p>
<pre><code>git reset --hard HEAD~1
</code></pre>
| <p>Delete the most recent commit, keeping the work you've done:</p> <pre><code>git reset --soft HEAD~1 </code></pre> <p>Delete the most recent commit, <strong>destroying the work</strong> you've done:</p> <pre><code>git reset --hard HEAD~1 </code></pre> | 119 | git | <h1>How do I delete unpushed git commits?</h1>
<p>I accidentally committed to the wrong branch.
How do I delete that commit?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,793 | git | # How do I delete unpushed git commits?
I accidentally committed to the wrong branch.
How do I delete that commit? | Delete the most recent commit, keeping the work you've done:
```
git reset --soft HEAD~1
```
Delete the most recent commit, **destroying the work** you've done:
```
git reset --hard HEAD~1
``` |
5188320 | How can I get a list of Git branches, ordered by most recent commit? | 2,122 | 2011-03-04 00:26:35 | <p>I want to get a list of all the branches in a Git repository with the "freshest" branches at the top, where the "freshest" branch is the one that's been committed to most recently (and is, therefore, more likely to be one I want to pay attention to).</p>
<p>Is there a way I can use Git to either (a) sort the list o... | 826,397 | 87,399 | 2025-05-11 08:16:55 | 5,188,364 | 2,981 | 2011-03-04 00:33:02 | 46,058 | 2024-10-19 15:49:57 | https://stackoverflow.com/q/5188320 | https://stackoverflow.com/a/5188364 | <p>Use the <strong><code>--sort=-committerdate</code></strong> option of <a href="http://www.kernel.org/pub/software/scm/git/docs/git-for-each-ref.html" rel="noreferrer"><code>git for-each-ref</code></a>;</p>
<p>Also available <a href="https://git-blame.blogspot.com/" rel="noreferrer">since Git 2.7.0</a> for <a href="h... | <p>Use the <strong><code>--sort=-committerdate</code></strong> option of <a href="http://www.kernel.org/pub/software/scm/git/docs/git-for-each-ref.html" rel="noreferrer"><code>git for-each-ref</code></a>;</p> <p>Also available <a href="https://git-blame.blogspot.com/" rel="noreferrer">since Git 2.7.0</a> for <a href="h... | 119, 456, 76220 | git, git-branch, version-control | <h1>How can I get a list of Git branches, ordered by most recent commit?</h1>
<p>I want to get a list of all the branches in a Git repository with the "freshest" branches at the top, where the "freshest" branch is the one that's been committed to most recently (and is, therefore, more likely to be one I want to pay att... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,794 | git | # How can I get a list of Git branches, ordered by most recent commit?
I want to get a list of all the branches in a Git repository with the "freshest" branches at the top, where the "freshest" branch is the one that's been committed to most recently (and is, therefore, more likely to be one I want to pay attention to... | Use the **`--sort=-committerdate`** option of [`git for-each-ref`](http://www.kernel.org/pub/software/scm/git/docs/git-for-each-ref.html);
Also available [since Git 2.7.0](https://git-blame.blogspot.com/) for [`git branch`](http://www.kernel.org/pub/software/scm/git/docs/git-branch.html):
# Basic Usage:
```
git for-... |
17563726 | How can I see the changes in a Git commit? | 2,405 | 2013-07-10 06:22:43 | <p>When I do <code>git diff COMMIT</code> I see the changes between that commit and HEAD (as far as I know), but I would like to see the changes that were made by that single commit.</p>
<p>I haven't found any obvious options on <code>diff</code> / <code>log</code> that will give me that output.</p>
| 2,106,204 | 52,817 | 2025-04-11 08:42:49 | 17,563,740 | 2,942 | 2013-07-10 06:23:49 | 1,761,499 | 2021-05-16 12:22:11 | https://stackoverflow.com/q/17563726 | https://stackoverflow.com/a/17563740 | <p>To see the diff for a particular <code>COMMIT</code> hash, where <code>COMMIT</code> is the hash of the commit:</p>
<p><code>git diff COMMIT~ COMMIT</code> will show you the difference between that <code>COMMIT</code>'s ancestor and the <code>COMMIT</code>. See the man pages for <a href="http://jk.gs/git-diff.html" ... | <p>To see the diff for a particular <code>COMMIT</code> hash, where <code>COMMIT</code> is the hash of the commit:</p> <p><code>git diff COMMIT~ COMMIT</code> will show you the difference between that <code>COMMIT</code>'s ancestor and the <code>COMMIT</code>. See the man pages for <a href="http://jk.gs/git-diff.html" ... | 119, 456, 606, 9033 | diff, git, git-diff, version-control | <h1>How can I see the changes in a Git commit?</h1>
<p>When I do <code>git diff COMMIT</code> I see the changes between that commit and HEAD (as far as I know), but I would like to see the changes that were made by that single commit.</p>
<p>I haven't found any obvious options on <code>diff</code> / <code>log</code> t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,795 | git | # How can I see the changes in a Git commit?
When I do `git diff COMMIT` I see the changes between that commit and HEAD (as far as I know), but I would like to see the changes that were made by that single commit.
I haven't found any obvious options on `diff` / `log` that will give me that output. | To see the diff for a particular `COMMIT` hash, where `COMMIT` is the hash of the commit:
`git diff COMMIT~ COMMIT` will show you the difference between that `COMMIT`'s ancestor and the `COMMIT`. See the man pages for [git diff](http://jk.gs/git-diff.html) for details about the command and [gitrevisions](http://jk.gs/... |
822811 | Showing which files have changed between two revisions | 2,380 | 2009-05-05 00:47:59 | <p>I want to merge two branches that have been separated for a while and wanted to know which files have been modified.</p>
<p>Came across this link: <a href="https://web.archive.org/web/20180830081303/http://linux.yyz.us/git-howto.html" rel="noreferrer">http://linux.yyz.us/git-howto.html</a> (moved to web.archive.org)... | 928,775 | 101,126 | 2024-11-28 18:00:37 | 822,859 | 2,937 | 2009-05-05 01:04:38 | 2,938 | 2024-11-28 18:00:37 | https://stackoverflow.com/q/822811 | https://stackoverflow.com/a/822859 | <p>To compare the current branch against <code>main</code> branch:</p>
<pre><code>$ git diff --name-status main
</code></pre>
<p>To compare any two branches:</p>
<pre><code>$ git diff --name-status firstbranch..yourBranchName
</code></pre>
<p>There are more options to <code>git diff</code> in the <a href="https://git-s... | <p>To compare the current branch against <code>main</code> branch:</p> <pre><code>$ git diff --name-status main </code></pre> <p>To compare any two branches:</p> <pre><code>$ git diff --name-status firstbranch..yourBranchName </code></pre> <p>There are more options to <code>git diff</code> in the <a href="https://git-s... | 119, 1879, 9033, 76220 | branch, git, git-branch, git-diff | <h1>Showing which files have changed between two revisions</h1>
<p>I want to merge two branches that have been separated for a while and wanted to know which files have been modified.</p>
<p>Came across this link: <a href="https://web.archive.org/web/20180830081303/http://linux.yyz.us/git-howto.html" rel="noreferrer">h... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,796 | git | # Showing which files have changed between two revisions
I want to merge two branches that have been separated for a while and wanted to know which files have been modified.
Came across this link: [http://linux.yyz.us/git-howto.html](https://web.archive.org/web/20180830081303/http://linux.yyz.us/git-howto.html) (move... | To compare the current branch against `main` branch:
```
$ git diff --name-status main
```
To compare any two branches:
```
$ git diff --name-status firstbranch..yourBranchName
```
There are more options to `git diff` in the [official documentation](https://git-scm.com/docs/git-diff) (and specifically the [`--name-... |
12254076 | How do I show my global Git configuration? | 1,839 | 2012-09-03 21:14:17 | <p>I'd like to show all configured Git sections.</p>
<p>I only found <code>git config --get core.editor</code>, and I'd like to output everything that's configured globally, not only the configured default editor.</p>
| 2,137,648 | 698,583 | 2025-07-25 13:32:58 | 12,254,105 | 2,803 | 2012-09-03 21:16:39 | 474,283 | 2020-01-20 23:45:29 | https://stackoverflow.com/q/12254076 | https://stackoverflow.com/a/12254105 | <p>You can use:</p>
<pre class="lang-sh prettyprint-override"><code>git config --list
</code></pre>
<p>or look at your <code>~/.gitconfig</code> file. The local configuration will be in your repository's <code>.git/config</code> file.</p>
<p>Use:</p>
<pre class="lang-sh prettyprint-override"><code>git config --list... | <p>You can use:</p> <pre class="lang-sh prettyprint-override"><code>git config --list </code></pre> <p>or look at your <code>~/.gitconfig</code> file. The local configuration will be in your repository's <code>.git/config</code> file.</p> <p>Use:</p> <pre class="lang-sh prettyprint-override"><code>git config --list... | 119 | git | <h1>How do I show my global Git configuration?</h1>
<p>I'd like to show all configured Git sections.</p>
<p>I only found <code>git config --get core.editor</code>, and I'd like to output everything that's configured globally, not only the configured default editor.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,797 | git | # How do I show my global Git configuration?
I'd like to show all configured Git sections.
I only found `git config --get core.editor`, and I'd like to output everything that's configured globally, not only the configured default editor. | You can use:
```
git config --list
```
or look at your `~/.gitconfig` file. The local configuration will be in your repository's `.git/config` file.
Use:
```
git config --list --show-origin
```
to see where that setting is defined (global, user, repo, etc...) |
5772192 | How can I reconcile detached HEAD with master/origin? | 1,765 | 2011-04-24 17:51:01 | <p>I'm new at the branching complexities of Git. I always work on a single branch and commit changes and then periodically push to my remote origin.</p>
<p>Somewhere recently, I did a reset of some files to get them out of commit staging, and later did a <code>rebase -i</code> to get rid of a couple recent local commi... | 1,303,076 | 73,297 | 2024-02-12 13:07:46 | 5,772,882 | 2,797 | 2011-04-24 19:56:33 | 193,688 | 2019-01-15 18:16:21 | https://stackoverflow.com/q/5772192 | https://stackoverflow.com/a/5772882 | <p>First, let’s clarify <a href="https://git-scm.com/book/en/v2/Git-Internals-Git-References" rel="noreferrer"><strong>what HEAD is</strong></a> and what it means when it is detached. </p>
<p>HEAD is the symbolic name for the currently checked out commit. When HEAD is not detached (the “normal”<sup>1</sup> situation:... | <p>First, let’s clarify <a href="https://git-scm.com/book/en/v2/Git-Internals-Git-References" rel="noreferrer"><strong>what HEAD is</strong></a> and what it means when it is detached. </p> <p>HEAD is the symbolic name for the currently checked out commit. When HEAD is not detached (the “normal”<sup>1</sup> situation:... | 119 | git | <h1>How can I reconcile detached HEAD with master/origin?</h1>
<p>I'm new at the branching complexities of Git. I always work on a single branch and commit changes and then periodically push to my remote origin.</p>
<p>Somewhere recently, I did a reset of some files to get them out of commit staging, and later did a <... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,798 | git | # How can I reconcile detached HEAD with master/origin?
I'm new at the branching complexities of Git. I always work on a single branch and commit changes and then periodically push to my remote origin.
Somewhere recently, I did a reset of some files to get them out of commit staging, and later did a `rebase -i` to ge... | First, let’s clarify [**what HEAD is**](https://git-scm.com/book/en/v2/Git-Internals-Git-References) and what it means when it is detached.
HEAD is the symbolic name for the currently checked out commit. When HEAD is not detached (the “normal”1 situation: you have a branch checked out), HEAD actually points to a branc... |
692246 | Undo working copy modifications of one file in Git | 2,122 | 2009-03-28 05:09:02 | <p>After the last commit, I modified a bunch of files in my working copy, but I want to undo the changes to one of those files, as in reset it to the same state as the most recent commit.</p>
<p>However, I only want to undo the working copy changes of just that one file alone, nothing else with it.</p>
<p>How do I do... | 1,024,222 | 35,364 | 2024-08-15 21:47:45 | 692,329 | 2,763 | 2009-03-28 06:12:51 | 69,755 | 2023-12-12 08:21:14 | https://stackoverflow.com/q/692246 | https://stackoverflow.com/a/692329 | <p>You can use</p>
<pre><code>git checkout -- file
</code></pre>
<p>You can do it without the <code>--</code> (as suggested by nimrodm), but if the filename looks like a branch or tag (or other revision identifier), it may get confused, so using <code>--</code> is best.</p>
<p>You can also check out a particular versio... | <p>You can use</p> <pre><code>git checkout -- file </code></pre> <p>You can do it without the <code>--</code> (as suggested by nimrodm), but if the filename looks like a branch or tag (or other revision identifier), it may get confused, so using <code>--</code> is best.</p> <p>You can also check out a particular versio... | 119, 456, 3346, 5310, 5766 | dvcs, file, git, undo, version-control | <h1>Undo working copy modifications of one file in Git</h1>
<p>After the last commit, I modified a bunch of files in my working copy, but I want to undo the changes to one of those files, as in reset it to the same state as the most recent commit.</p>
<p>However, I only want to undo the working copy changes of just th... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,799 | git | # Undo working copy modifications of one file in Git
After the last commit, I modified a bunch of files in my working copy, but I want to undo the changes to one of those files, as in reset it to the same state as the most recent commit.
However, I only want to undo the working copy changes of just that one file alon... | You can use
```
git checkout -- file
```
You can do it without the `--` (as suggested by nimrodm), but if the filename looks like a branch or tag (or other revision identifier), it may get confused, so using `--` is best.
You can also check out a particular version of a file:
```
git checkout v1.2.3 -- file ... |
278192 | View the change history of a file using Git versioning | 3,994 | 2008-11-10 15:42:32 | <p>How do I view the history of an individual file with complete details of what has changed?</p>
<p><code>git log -- [filename]</code> shows me the commit history of a file, but how do I see the file content that changed?</p>
| 2,653,213 | 36,214 | 2025-03-17 11:25:52 | 1,321,962 | 2,728 | 2009-08-24 12:05:51 | 48,696 | 2022-07-10 21:54:42 | https://stackoverflow.com/q/278192 | https://stackoverflow.com/a/1321962 | <p>For a graphical view, use <a href="https://git-scm.com/docs/gitk/" rel="noreferrer"><code>gitk</code></a>:</p>
<pre><code>gitk [filename]
</code></pre>
<p>To follow the file across file renames:</p>
<pre><code>gitk --follow [filename]
</code></pre>
| <p>For a graphical view, use <a href="https://git-scm.com/docs/gitk/" rel="noreferrer"><code>gitk</code></a>:</p> <pre><code>gitk [filename] </code></pre> <p>To follow the file across file renames:</p> <pre><code>gitk --follow [filename] </code></pre> | 119, 47913 | git, git-log | <h1>View the change history of a file using Git versioning</h1>
<p>How do I view the history of an individual file with complete details of what has changed?</p>
<p><code>git log -- [filename]</code> shows me the commit history of a file, but how do I see the file content that changed?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,800 | git | # View the change history of a file using Git versioning
How do I view the history of an individual file with complete details of what has changed?
`git log -- [filename]` shows me the commit history of a file, but how do I see the file content that changed? | For a graphical view, use [`gitk`](https://git-scm.com/docs/gitk/):
```
gitk [filename]
```
To follow the file across file renames:
```
gitk --follow [filename]
``` |
1260748 | How do I remove a submodule? | 4,758 | 2009-08-11 14:31:24 | <p>How do I remove a Git submodule?
Why can't I do
<code>git submodule rm module_name</code>?</p>
| 1,976,998 | 46,642 | 2025-05-15 17:20:13 | 16,162,000 | 2,691 | 2013-04-23 05:57:49 | 6,309 | 2021-04-15 13:59:07 | https://stackoverflow.com/q/1260748 | https://stackoverflow.com/a/16162000 | <p>Since <a href="https://github.com/git/git/blob/v1.8.3-rc0/Documentation/RelNotes/1.8.3.txt#L135-L137" rel="noreferrer">git1.8.3 (April 22d, 2013)</a>:</p>
<blockquote>
<p>There was no Porcelain way to say "I no longer am interested in this submodule", once you express your interest in a submodule with &quo... | <p>Since <a href="https://github.com/git/git/blob/v1.8.3-rc0/Documentation/RelNotes/1.8.3.txt#L135-L137" rel="noreferrer">git1.8.3 (April 22d, 2013)</a>:</p> <blockquote> <p>There was no Porcelain way to say "I no longer am interested in this submodule", once you express your interest in a submodule with &quo... | 119, 41612 | git, git-submodules | <h1>How do I remove a submodule?</h1>
<p>How do I remove a Git submodule?
Why can't I do
<code>git submodule rm module_name</code>?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,801 | git | # How do I remove a submodule?
How do I remove a Git submodule?
Why can't I do
`git submodule rm module_name`? | Since [git1.8.3 (April 22d, 2013)](https://github.com/git/git/blob/v1.8.3-rc0/Documentation/RelNotes/1.8.3.txt#L135-L137):
> There was no Porcelain way to say "I no longer am interested in this submodule", once you express your interest in a submodule with "`git submodule init`".
> "**`git submodule deinit`**" is th... |
7677736 | How to "git diff" the working tree to the stash? | 1,957 | 2011-10-06 16:48:59 | <p>How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them!</p>
| 715,661 | 310,678 | 2024-08-26 05:28:22 | 7,677,755 | 2,668 | 2011-10-06 16:50:29 | 148,870 | 2017-01-18 09:28:53 | https://stackoverflow.com/q/7677736 | https://stackoverflow.com/a/7677755 | <p>See the most recent stash:</p>
<pre><code>git stash show -p
</code></pre>
<p>See an arbitrary stash:</p>
<pre><code>git stash show -p stash@{1}
</code></pre>
<p>From the <code>git stash</code> manpages:</p>
<blockquote>
<p>By default, the command shows the diffstat, but it will accept any
format known to gi... | <p>See the most recent stash:</p> <pre><code>git stash show -p </code></pre> <p>See an arbitrary stash:</p> <pre><code>git stash show -p stash@{1} </code></pre> <p>From the <code>git stash</code> manpages:</p> <blockquote> <p>By default, the command shows the diffstat, but it will accept any format known to gi... | 119, 13091 | git, git-stash | <h1>How to "git diff" the working tree to the stash?</h1>
<p>How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them!</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,803 | git | # How to "git diff" the working tree to the stash?
How can I see the changes un-stashing will make to the current working tree? I would like to know what changes will be made before applying them! | See the most recent stash:
```
git stash show -p
```
See an arbitrary stash:
```
git stash show -p stash@{1}
```
From the `git stash` manpages:
> By default, the command shows the diffstat, but it will accept any
> format known to git diff (e.g., git stash show -p stash@{1} to view
> the second most recent stash i... |
15286075 | Difference between git stash pop and git stash apply | 1,698 | 2013-03-08 03:14:02 | <p>What is the difference between <code>git stash pop</code> and <code>git stash apply</code>?</p>
<p>They seemingly worked similarly</p>
| 945,588 | 1,044,366 | 2025-09-25 23:23:52 | 15,286,090 | 2,664 | 2013-03-08 03:15:45 | 4,323 | 2019-02-03 01:05:47 | https://stackoverflow.com/q/15286075 | https://stackoverflow.com/a/15286090 | <p><code>git stash pop</code> <strong>throws away</strong> the (topmost, by default) stash after applying it, whereas <code>git stash apply</code> <strong>leaves it in the stash list</strong> for possible later reuse (or you can then <code>git stash drop</code> it). </p>
<p>This happens unless there are conflicts afte... | <p><code>git stash pop</code> <strong>throws away</strong> the (topmost, by default) stash after applying it, whereas <code>git stash apply</code> <strong>leaves it in the stash list</strong> for possible later reuse (or you can then <code>git stash drop</code> it). </p> <p>This happens unless there are conflicts afte... | 119, 13091 | git, git-stash | <h1>Difference between git stash pop and git stash apply</h1>
<p>What is the difference between <code>git stash pop</code> and <code>git stash apply</code>?</p>
<p>They seemingly worked similarly</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,804 | git | # Difference between git stash pop and git stash apply
What is the difference between `git stash pop` and `git stash apply`?
They seemingly worked similarly | `git stash pop` **throws away** the (topmost, by default) stash after applying it, whereas `git stash apply` **leaves it in the stash list** for possible later reuse (or you can then `git stash drop` it).
This happens unless there are conflicts after `git stash pop`, in which case it will not remove the stash, leaving... |
6217156 | Break a previous commit into multiple commits | 1,910 | 2011-06-02 16:11:12 | <p>Without creating a branch and doing a bunch of funky work on a new branch, is it possible to break a single commit into a few different commits after it's been committed to the local repository?</p>
| 646,420 | 191,450 | 2024-11-13 11:23:30 | 6,217,314 | 2,637 | 2011-06-02 16:26:02 | 238,886 | 2024-05-07 12:04:59 | https://stackoverflow.com/q/6217156 | https://stackoverflow.com/a/6217314 | <p><a href="http://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_changing_multiple" rel="noreferrer"><code>git rebase -i</code></a> will do it.</p>
<p>First, start with a clean working directory: <code>git status</code> should show no pending modifications, deletions, or additions.</p>
<p>Now, you have to decide ... | <p><a href="http://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_changing_multiple" rel="noreferrer"><code>git rebase -i</code></a> will do it.</p> <p>First, start with a clean working directory: <code>git status</code> should show no pending modifications, deletions, or additions.</p> <p>Now, you have to decide ... | 119 | git | <h1>Break a previous commit into multiple commits</h1>
<p>Without creating a branch and doing a bunch of funky work on a new branch, is it possible to break a single commit into a few different commits after it's been committed to the local repository?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,806 | git | # Break a previous commit into multiple commits
Without creating a branch and doing a bunch of funky work on a new branch, is it possible to break a single commit into a few different commits after it's been committed to the local repository? | [`git rebase -i`](http://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_changing_multiple) will do it.
First, start with a clean working directory: `git status` should show no pending modifications, deletions, or additions.
Now, you have to decide which commit(s) you want to split.
### A) Splitting the most rec... |
1753070 | How do I configure git to ignore some files locally? | 1,926 | 2009-11-18 01:36:47 | <p>Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don't want to commit git config changes for every single little random untracked file I have in my local branches.</p>
| 784,356 | 66,475 | 2025-04-04 22:11:54 | 1,753,078 | 2,632 | 2009-11-18 01:38:18 | 19,750 | 2020-02-26 05:03:57 | https://stackoverflow.com/q/1753070 | https://stackoverflow.com/a/1753078 | <p>From <a href="http://git-scm.com/docs/gitignore" rel="noreferrer">the relevant Git documentation</a>:</p>
<blockquote>
<p>Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specifi... | <p>From <a href="http://git-scm.com/docs/gitignore" rel="noreferrer">the relevant Git documentation</a>:</p> <blockquote> <p>Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specifi... | 119, 4333, 25056 | git, gitignore, ignore | <h1>How do I configure git to ignore some files locally?</h1>
<p>Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don't want to commit git config changes for every single little random untracked file I have in my local bran... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,807 | git | # How do I configure git to ignore some files locally?
Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don't want to commit git config changes for every single little random untracked file I have in my local branches. | From [the relevant Git documentation](http://git-scm.com/docs/gitignore):
> Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the `$GIT_... |
14075581 | git undo all uncommitted or unsaved changes | 1,367 | 2012-12-28 20:46:53 | <p>I'm trying to undo all changes since my last commit. I tried <code>git reset --hard</code> and <code>git reset --hard HEAD</code> after viewing <a href="https://stackoverflow.com/questions/7999259/git-how-to-perform-the-tfs-equivalent-of-undo-pending-changes">this post</a>. I responds with head is now at 18c3773... ... | 1,560,774 | 504,963 | 2024-08-04 20:50:40 | 14,075,772 | 2,609 | 2012-12-28 21:04:38 | 1,734,130 | 2024-08-04 20:50:40 | https://stackoverflow.com/q/14075581 | https://stackoverflow.com/a/14075772 | <ul>
<li><p>This will unstage all files you might have staged with <code>git add</code>:</p>
<pre><code> git reset
</code></pre>
</li>
<li><p>This will revert all local uncommitted changes (should be executed in repo root):</p>
<pre><code> git checkout .
</code></pre>
<p>You can also revert uncommitted changes only t... | <ul> <li><p>This will unstage all files you might have staged with <code>git add</code>:</p> <pre><code> git reset </code></pre> </li> <li><p>This will revert all local uncommitted changes (should be executed in repo root):</p> <pre><code> git checkout . </code></pre> <p>You can also revert uncommitted changes only t... | 119, 1231, 5766, 51381 | command-line, git, git-reset, undo | <h1>git undo all uncommitted or unsaved changes</h1>
<p>I'm trying to undo all changes since my last commit. I tried <code>git reset --hard</code> and <code>git reset --hard HEAD</code> after viewing <a href="https://stackoverflow.com/questions/7999259/git-how-to-perform-the-tfs-equivalent-of-undo-pending-changes">this... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,808 | git | # git undo all uncommitted or unsaved changes
I'm trying to undo all changes since my last commit. I tried `git reset --hard` and `git reset --hard HEAD` after viewing [this post](https://stackoverflow.com/questions/7999259/git-how-to-perform-the-tfs-equivalent-of-undo-pending-changes). I responds with head is now at ... | - This will unstage all files you might have staged with `git add`:
```
git reset
```
- This will revert all local uncommitted changes (should be executed in repo root):
```
git checkout .
```
You can also revert uncommitted changes only to particular file or directory:
```
git checkout [som... |
160608 | Do a "git export" (like "svn export")? | 2,583 | 2008-10-02 02:21:33 | <p>I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the <code>.git</code> repository directory. There are at least three methods I know of:</p>
<ol>
<li><code>git clone</code> followed by removing the <code>.git</code> repository directory.</li>
<li><a hr... | 783,509 | 893 | 2025-12-07 16:20:06 | 163,769 | 2,599 | 2008-10-02 18:13:14 | 19,563 | 2023-07-24 18:46:47 | https://stackoverflow.com/q/160608 | https://stackoverflow.com/a/163769 | <p>Probably the simplest way to achieve this is with <a href="https://git-scm.com/docs/git-archive" rel="noreferrer"><code>git archive</code></a>. If you really need just the expanded tree you can do something like this.</p>
<pre><code>git archive master | tar -x -C /somewhere/else
</code></pre>
<p>Most of the time tha... | <p>Probably the simplest way to achieve this is with <a href="https://git-scm.com/docs/git-archive" rel="noreferrer"><code>git archive</code></a>. If you really need just the expanded tree you can do something like this.</p> <pre><code>git archive master | tar -x -C /somewhere/else </code></pre> <p>Most of the time tha... | 119, 4167, 27566, 81662 | export, git, git-archive, svn-export | <h1>Do a "git export" (like "svn export")?</h1>
<p>I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the <code>.git</code> repository directory. There are at least three methods I know of:</p>
<ol>
<li><code>git clone</code> followed by removing the <code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,809 | git | # Do a "git export" (like "svn export")?
I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the `.git` repository directory. There are at least three methods I know of:
1. `git clone` followed by removing the `.git` repository directory.
2. [`git checkout-index`](h... | Probably the simplest way to achieve this is with [`git archive`](https://git-scm.com/docs/git-archive). If you really need just the expanded tree you can do something like this.
```
git archive master | tar -x -C /somewhere/else
```
Most of the time that I need to 'export' something from git, I want a compressed arc... |
2364147 | How to get just one file from another branch | 2,140 | 2010-03-02 15:15:18 | <p>I have a <code>main</code> branch with a file called <code>app.js</code>. I made changes to this file on an <code>experiment</code> branch.</p>
<p>I want to apply only the changes made to <code>app.js</code> from <code>experiment</code> onto the <code>main</code> branch.</p>
| 1,572,010 | 253,470 | 2024-06-28 17:10:33 | 2,364,223 | 2,598 | 2010-03-02 15:23:21 | 6,309 | 2023-07-01 11:09:58 | https://stackoverflow.com/q/2364147 | https://stackoverflow.com/a/2364223 | <pre><code>git checkout main # first get back to main
git checkout experiment -- app.js # then copy the version of app.js
# from branch "experiment"
</code></pre>
<p>See also <em><a href="https://stackoverflow.com/q/692246/6309">Undo working copy modification... | <pre><code>git checkout main # first get back to main git checkout experiment -- app.js # then copy the version of app.js # from branch "experiment" </code></pre> <p>See also <em><a href="https://stackoverflow.com/q/692246/6309">Undo working copy modification... | 119, 37230, 76220 | git, git-branch, git-checkout | <h1>How to get just one file from another branch</h1>
<p>I have a <code>main</code> branch with a file called <code>app.js</code>. I made changes to this file on an <code>experiment</code> branch.</p>
<p>I want to apply only the changes made to <code>app.js</code> from <code>experiment</code> onto the <code>main</code>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,810 | git | # How to get just one file from another branch
I have a `main` branch with a file called `app.js`. I made changes to this file on an `experiment` branch.
I want to apply only the changes made to `app.js` from `experiment` onto the `main` branch. | ```
git checkout main # first get back to main
git checkout experiment -- app.js # then copy the version of app.js
# from branch "experiment"
```
See also *[Undo working copy modifications of one file in Git](https://stackoverflow.com/q/692246/6309)*.
---
### Update... |
1911109 | How do I clone a specific Git branch? | 4,214 | 2009-12-15 23:06:50 | <p>Git clone will clone remote branch into local.</p>
<p>Is there any way to clone a specific branch by myself without switching branches on the remote repository?</p>
| 5,508,871 | 207,419 | 2025-04-27 22:34:25 | 1,911,126 | 2,576 | 2009-12-15 23:09:29 | 95,382 | 2020-10-14 17:01:05 | https://stackoverflow.com/q/1911109 | https://stackoverflow.com/a/1911126 | <pre><code>git clone --single-branch --branch <branchname> <remote-repo>
</code></pre>
<p>The <code>--single-branch</code> option is valid from version <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.10.txt" rel="noreferrer">1.7.10</a> and later.</p>
<p>Please see also the <a href... | <pre><code>git clone --single-branch --branch <branchname> <remote-repo> </code></pre> <p>The <code>--single-branch</code> option is valid from version <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.10.txt" rel="noreferrer">1.7.10</a> and later.</p> <p>Please see also the <a href... | 119, 1879, 34099 | branch, git, git-clone | <h1>How do I clone a specific Git branch?</h1>
<p>Git clone will clone remote branch into local.</p>
<p>Is there any way to clone a specific branch by myself without switching branches on the remote repository?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,812 | git | # How do I clone a specific Git branch?
Git clone will clone remote branch into local.
Is there any way to clone a specific branch by myself without switching branches on the remote repository? | ```
git clone --single-branch --branch <branchname> <remote-repo>
```
The `--single-branch` option is valid from version [1.7.10](https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.10.txt) and later.
Please see also the [other answer](https://stackoverflow.com/a/4568323/134077) which many people prefer... |
2763006 | Make the current Git branch a master branch | 2,126 | 2010-05-04 05:30:52 | <p>I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.</p>
<p>Then, tens of commits later, I realized the branch is in much better state than the master, so I want the branch to "become" the master and disregard the changes on master.</p>
<p>I cannot merge it, beca... | 1,016,584 | 101,152 | 2024-05-13 14:23:23 | 2,763,118 | 2,576 | 2010-05-04 06:00:07 | 119,963 | 2024-05-13 14:23:23 | https://stackoverflow.com/q/2763006 | https://stackoverflow.com/a/2763118 | <p>The problem with the other two answers is that the new master doesn't have the old master as an ancestor, so when you push it, everyone else will get messed up. This is what you want to do:</p>
<pre><code>git checkout better_branch # This is the branch whose commits you want to keep
git merge --strategy=our... | <p>The problem with the other two answers is that the new master doesn't have the old master as an ancestor, so when you push it, everyone else will get messed up. This is what you want to do:</p> <pre><code>git checkout better_branch # This is the branch whose commits you want to keep git merge --strategy=our... | 119 | git | <h1>Make the current Git branch a master branch</h1>
<p>I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.</p>
<p>Then, tens of commits later, I realized the branch is in much better state than the master, so I want the branch to "become" the master and disregard t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,813 | git | # Make the current Git branch a master branch
I have a repository in Git. I made a branch, then did some changes both to the master and to the branch.
Then, tens of commits later, I realized the branch is in much better state than the master, so I want the branch to "become" the master and disregard the changes on ma... | The problem with the other two answers is that the new master doesn't have the old master as an ancestor, so when you push it, everyone else will get messed up. This is what you want to do:
```
git checkout better_branch # This is the branch whose commits you want to keep
git merge --strategy=ours master #... |
38004148 | Another Git process seems to be running in this repository | 1,287 | 2016-06-24 00:59:24 | <p>I'm trying to learn how to use Git and have created a small project with an HTML, CSS, and JavaScript file. I made a branch from my basically empty project and then made some changes to my code. I tried staging the changes, but I get the following error message:</p>
<pre><code>Another git process seems to be running... | 1,201,782 | 6,242,376 | 2025-12-15 13:27:43 | 38,004,193 | 2,565 | 2016-06-24 01:05:37 | 4,498,523 | 2023-01-13 22:59:34 | https://stackoverflow.com/q/38004148 | https://stackoverflow.com/a/38004193 | <p>Try deleting <code>index.lock</code> file in your <code>.git</code> directory or in one of your <strong>worktrees</strong> <code>.git/worktrees/*/index.lock</code> if you are in a worktree.</p>
<pre class="lang-none prettyprint-override"><code>rm -f .git/index.lock
</code></pre>
<p>Such problems generally occur when... | <p>Try deleting <code>index.lock</code> file in your <code>.git</code> directory or in one of your <strong>worktrees</strong> <code>.git/worktrees/*/index.lock</code> if you are in a worktree.</p> <pre class="lang-none prettyprint-override"><code>rm -f .git/index.lock </code></pre> <p>Such problems generally occur when... | 119 | git | <h1>Another Git process seems to be running in this repository</h1>
<p>I'm trying to learn how to use Git and have created a small project with an HTML, CSS, and JavaScript file. I made a branch from my basically empty project and then made some changes to my code. I tried staging the changes, but I get the following e... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,814 | git | # Another Git process seems to be running in this repository
I'm trying to learn how to use Git and have created a small project with an HTML, CSS, and JavaScript file. I made a branch from my basically empty project and then made some changes to my code. I tried staging the changes, but I get the following error mess... | Try deleting `index.lock` file in your `.git` directory or in one of your **worktrees** `.git/worktrees/*/index.lock` if you are in a worktree.
```
rm -f .git/index.lock
```
Such problems generally occur when you execute two `git` commands simultaneously; maybe one from the command prompt and one from an IDE. |
5473 | How can I undo git reset --hard HEAD~1? | 1,713 | 2008-08-07 23:22:51 | <p>Is it possible to undo the changes caused by the following command? If so, how?</p>
<pre><code>git reset --hard HEAD~1
</code></pre>
| 964,051 | 85 | 2025-12-08 02:09:45 | 21,778 | 2,515 | 2008-08-22 04:36:02 | 2,063 | 2009-01-29 05:35:42 | https://stackoverflow.com/q/5473 | https://stackoverflow.com/a/21778 | <p>Pat Notz is correct. You can get the commit back so long as it's been within a few days. git only garbage collects after about a month or so unless you explicitly tell it to remove newer blobs.</p>
<pre><code>$ git init
Initialized empty Git repository in .git/
$ echo "testing reset" > file1
$ git add file1
$... | <p>Pat Notz is correct. You can get the commit back so long as it's been within a few days. git only garbage collects after about a month or so unless you explicitly tell it to remove newer blobs.</p> <pre><code>$ git init Initialized empty Git repository in .git/ $ echo "testing reset" > file1 $ git add file1 $... | 119, 456, 51381 | git, git-reset, version-control | <h1>How can I undo git reset --hard HEAD~1?</h1>
<p>Is it possible to undo the changes caused by the following command? If so, how?</p>
<pre><code>git reset --hard HEAD~1
</code></pre>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,815 | git | # How can I undo git reset --hard HEAD~1?
Is it possible to undo the changes caused by the following command? If so, how?
```
git reset --hard HEAD~1
``` | Pat Notz is correct. You can get the commit back so long as it's been within a few days. git only garbage collects after about a month or so unless you explicitly tell it to remove newer blobs.
```
$ git init
Initialized empty Git repository in .git/
$ echo "testing reset" > file1
$ git add file1
$ git commit -m 'add... |
1670970 | How to cherry-pick multiple commits | 1,663 | 2009-11-04 00:07:03 | <p>I have two branches. Commit <code>a</code> is the head of one, while the other has <code>b</code>, <code>c</code>, <code>d</code>, <code>e</code> and <code>f</code> on top of <code>a</code>. I want to move <code>c</code>, <code>d</code>, <code>e</code> and <code>f</code> to first branch without commit <code>b</code>... | 1,334,217 | 96,823 | 2025-04-16 15:05:42 | 3,933,416 | 2,502 | 2010-10-14 13:08:39 | 121,260 | 2025-04-13 01:14:16 | https://stackoverflow.com/q/1670970 | https://stackoverflow.com/a/3933416 | <p>Git 1.7.2 introduced the ability to cherry-pick a range of commits. From the <a href="https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.2.txt" rel="noreferrer">release notes</a>:</p>
<blockquote>
<p><code>git cherry-pick</code> learned to pick a range of commits
(e.g. <code>cherry-pick A..B</code> and... | <p>Git 1.7.2 introduced the ability to cherry-pick a range of commits. From the <a href="https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.2.txt" rel="noreferrer">release notes</a>:</p> <blockquote> <p><code>git cherry-pick</code> learned to pick a range of commits (e.g. <code>cherry-pick A..B</code> and... | 119, 29934, 36489, 78810 | cherry-pick, git, git-cherry-pick, git-rebase | <h1>How to cherry-pick multiple commits</h1>
<p>I have two branches. Commit <code>a</code> is the head of one, while the other has <code>b</code>, <code>c</code>, <code>d</code>, <code>e</code> and <code>f</code> on top of <code>a</code>. I want to move <code>c</code>, <code>d</code>, <code>e</code> and <code>f</code> ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,816 | git | # How to cherry-pick multiple commits
I have two branches. Commit `a` is the head of one, while the other has `b`, `c`, `d`, `e` and `f` on top of `a`. I want to move `c`, `d`, `e` and `f` to first branch without commit `b`. Using cherry pick it is easy: checkout first branch cherry-pick one by one `c` to `f` and reba... | Git 1.7.2 introduced the ability to cherry-pick a range of commits. From the [release notes](https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.2.txt):
> `git cherry-pick` learned to pick a range of commits
> (e.g. `cherry-pick A..B` and `cherry-pick --stdin`), so did `git revert`; these do not support t... |
25436312 | Gitignore not working | 1,080 | 2014-08-21 21:34:26 | <p>My <code>.gitignore</code> file isn't working for some reason, and no amount of Googling has been able to fix it. Here is what I have:</p>
<pre><code>*.apk
*.ap_
*.dex
*.class
**/bin/
**/gen/
.gradle/
build/
local.properties
**/proguard/
*.log
</code></pre>
<p>It's in the directory <code>master</code>, which is my... | 1,089,364 | 3,280,133 | 2025-03-25 02:50:59 | 25,436,481 | 2,496 | 2014-08-21 21:46:22 | 1,333,975 | 2021-02-25 15:44:56 | https://stackoverflow.com/q/25436312 | https://stackoverflow.com/a/25436481 | <p>The files/folder in your version control will not just delete themselves just because you added them to the <code>.gitignore</code>. They are already in the repository and you have to remove them. You can just do that with this:</p>
<p><strong>Remember to commit everything you've changed before you do this!</strong>... | <p>The files/folder in your version control will not just delete themselves just because you added them to the <code>.gitignore</code>. They are already in the repository and you have to remove them. You can just do that with this:</p> <p><strong>Remember to commit everything you've changed before you do this!</strong>... | 119, 25056 | git, gitignore | <h1>Gitignore not working</h1>
<p>My <code>.gitignore</code> file isn't working for some reason, and no amount of Googling has been able to fix it. Here is what I have:</p>
<pre><code>*.apk
*.ap_
*.dex
*.class
**/bin/
**/gen/
.gradle/
build/
local.properties
**/proguard/
*.log
</code></pre>
<p>It's in the directory <... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,817 | git | # Gitignore not working
My `.gitignore` file isn't working for some reason, and no amount of Googling has been able to fix it. Here is what I have:
```
*.apk
*.ap_
*.dex
*.class
**/bin/
**/gen/
.gradle/
build/
local.properties
**/proguard/
*.log
```
It's in the directory `master`, which is my git repo. I'm running G... | The files/folder in your version control will not just delete themselves just because you added them to the `.gitignore`. They are already in the repository and you have to remove them. You can just do that with this:
**Remember to commit everything you've changed before you do this!**
```
git rm -rf --cached .
git a... |
22575662 | Filename too long in Git for Windows | 1,659 | 2014-03-22 09:14:24 | <p>I'm using <code>Git-1.9.0-preview20140217</code> for Windows. As I know, this release should fix the issue with too long filenames. But not for me.</p>
<p>Surely I'm doing something wrong: I did <code>git config core.longpaths true</code> and <code>git add .</code> and then <code>git commit</code>. Everything went w... | 1,659,120 | 453,024 | 2025-12-10 23:56:55 | 22,575,737 | 2,468 | 2014-03-22 09:24:15 | 2,389,707 | 2024-07-16 00:32:16 | https://stackoverflow.com/q/22575662 | https://stackoverflow.com/a/22575737 | <p>Git has a limit of 4096 characters for a filename, except on Windows when Git is compiled with msys. It uses an older version of the Windows API and there's a limit of 260 characters for a filename.</p>
<p>So as far as I understand this, it's a limitation of msys and not of Git. You can read the details here:
<a hre... | <p>Git has a limit of 4096 characters for a filename, except on Windows when Git is compiled with msys. It uses an older version of the Windows API and there's a limit of 260 characters for a filename.</p> <p>So as far as I understand this, it's a limitation of msys and not of Git. You can read the details here: <a hre... | 64, 119 | git, windows | <h1>Filename too long in Git for Windows</h1>
<p>I'm using <code>Git-1.9.0-preview20140217</code> for Windows. As I know, this release should fix the issue with too long filenames. But not for me.</p>
<p>Surely I'm doing something wrong: I did <code>git config core.longpaths true</code> and <code>git add .</code> and t... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,819 | git | # Filename too long in Git for Windows
I'm using `Git-1.9.0-preview20140217` for Windows. As I know, this release should fix the issue with too long filenames. But not for me.
Surely I'm doing something wrong: I did `git config core.longpaths true` and `git add .` and then `git commit`. Everything went well. But when... | Git has a limit of 4096 characters for a filename, except on Windows when Git is compiled with msys. It uses an older version of the Windows API and there's a limit of 260 characters for a filename.
So as far as I understand this, it's a limitation of msys and not of Git. You can read the details here:
<https://github... |
936249 | How to stop tracking and ignore changes to a file in Git? | 2,116 | 2009-06-01 19:08:16 | <p>I have cloned a project that includes some <code>.csproj</code> files. I don't need/like my local <code>csproj</code> files being tracked by Git (or being brought up when creating a patch), but clearly they are needed in the project.</p>
<p>I have added <code>*.csproj</code> to my LOCAL <code>.gitignore</code>, but... | 919,319 | 39,758 | 2024-08-02 14:08:11 | 936,290 | 2,458 | 2009-06-01 19:16:19 | 64,290 | 2017-08-23 12:28:13 | https://stackoverflow.com/q/936249 | https://stackoverflow.com/a/936290 | <p>Just calling <code>git rm --cached</code> on each of the files you want to remove from revision control should be fine. As long as your local ignore patterns are correct you won't see these files included in the output of git status.</p>
<p>Note that this solution removes the files from the repository, so all devel... | <p>Just calling <code>git rm --cached</code> on each of the files you want to remove from revision control should be fine. As long as your local ignore patterns are correct you won't see these files included in the output of git status.</p> <p>Note that this solution removes the files from the repository, so all devel... | 119 | git | <h1>How to stop tracking and ignore changes to a file in Git?</h1>
<p>I have cloned a project that includes some <code>.csproj</code> files. I don't need/like my local <code>csproj</code> files being tracked by Git (or being brought up when creating a patch), but clearly they are needed in the project.</p>
<p>I have a... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,820 | git | # How to stop tracking and ignore changes to a file in Git?
I have cloned a project that includes some `.csproj` files. I don't need/like my local `csproj` files being tracked by Git (or being brought up when creating a patch), but clearly they are needed in the project.
I have added `*.csproj` to my LOCAL `.gitignor... | Just calling `git rm --cached` on each of the files you want to remove from revision control should be fine. As long as your local ignore patterns are correct you won't see these files included in the output of git status.
Note that this solution removes the files from the repository, so all developers would need to m... |
6919121 | Why there are two ways to unstage a file in Git? | 1,528 | 2011-08-02 21:50:49 | <p>Sometimes git suggests <code>git rm --cached</code> to unstage a file, sometimes <code>git reset HEAD file</code>. When should I use which?</p>
<pre><code>D:\code\gt2>git init
Initialized empty Git repository in D:/code/gt2/.git/
D:\code\gt2>touch a
D:\code\gt2>git status
# On branch master
#
# Initial com... | 1,516,423 | 817,740 | 2023-11-07 08:00:42 | 6,919,257 | 2,418 | 2011-08-02 22:03:13 | 839,646 | 2019-12-12 13:34:06 | https://stackoverflow.com/q/6919121 | https://stackoverflow.com/a/6919257 | <p><code>git rm --cached <filePath></code> <strong>does not unstage</strong> a file, it actually <strong>stages the removal of the file(s)</strong> from the repo (assuming it was already committed before) but leaves the file in your working tree (leaving you with an untracked file).</p>
<p><code>git reset -- <... | <p><code>git rm --cached <filePath></code> <strong>does not unstage</strong> a file, it actually <strong>stages the removal of the file(s)</strong> from the repo (assuming it was already committed before) but leaves the file in your working tree (leaving you with an untracked file).</p> <p><code>git reset -- <... | 119, 51381, 112901 | git, git-reset, git-rm | <h1>Why there are two ways to unstage a file in Git?</h1>
<p>Sometimes git suggests <code>git rm --cached</code> to unstage a file, sometimes <code>git reset HEAD file</code>. When should I use which?</p>
<pre><code>D:\code\gt2>git init
Initialized empty Git repository in D:/code/gt2/.git/
D:\code\gt2>touch a
D:... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,821 | git | # Why there are two ways to unstage a file in Git?
Sometimes git suggests `git rm --cached` to unstage a file, sometimes `git reset HEAD file`. When should I use which?
```
D:\code\gt2>git init
Initialized empty Git repository in D:/code/gt2/.git/
D:\code\gt2>touch a
D:\code\gt2>git status
# On branch master
#
# Ini... | `git rm --cached <filePath>` **does not unstage** a file, it actually **stages the removal of the file(s)** from the repo (assuming it was already committed before) but leaves the file in your working tree (leaving you with an untracked file).
`git reset -- <filePath>` will **unstage** any staged changes for the given... |
4470523 | Create a branch in Git from another branch | 1,758 | 2010-12-17 12:39:03 | <p>I have two branches: <strong>master</strong> and <strong>dev</strong></p>
<p>I want to create a "feature branch" from the <em>dev</em> branch.</p>
<p>Currently on the branch <em>dev</em>, I do:</p>
<pre><code>git checkout -b myfeature dev
</code></pre>
<p>... (some work)</p>
<pre><code>git commit -am "... | 3,546,581 | 528,127 | 2025-04-13 01:08:22 | 4,470,822 | 2,409 | 2010-12-17 13:23:08 | 41,116 | 2024-11-08 20:53:43 | https://stackoverflow.com/q/4470523 | https://stackoverflow.com/a/4470822 | <p>If you like the method in the link you've posted, have a look at <a href="https://github.com/nvie/gitflow" rel="noreferrer">Git Flow</a>.</p>
<p>It's a set of scripts he created for that workflow.</p>
<p>But to answer your question:</p>
<pre><code>git checkout -b myFeature dev
</code></pre>
<p>Creates the <em>myFeat... | <p>If you like the method in the link you've posted, have a look at <a href="https://github.com/nvie/gitflow" rel="noreferrer">Git Flow</a>.</p> <p>It's a set of scripts he created for that workflow.</p> <p>But to answer your question:</p> <pre><code>git checkout -b myFeature dev </code></pre> <p>Creates the <em>myFeat... | 119, 55606, 64339, 76220 | git, git-branch, git-flow, git-workflow | <h1>Create a branch in Git from another branch</h1>
<p>I have two branches: <strong>master</strong> and <strong>dev</strong></p>
<p>I want to create a "feature branch" from the <em>dev</em> branch.</p>
<p>Currently on the branch <em>dev</em>, I do:</p>
<pre><code>git checkout -b myfeature dev
</code></pre>
<p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,822 | git | # Create a branch in Git from another branch
I have two branches: **master** and **dev**
I want to create a "feature branch" from the *dev* branch.
Currently on the branch *dev*, I do:
```
git checkout -b myfeature dev
```
... (some work)
```
git commit -am "blablabla"
git push origin myfeature
```
But, after vi... | If you like the method in the link you've posted, have a look at [Git Flow](https://github.com/nvie/gitflow).
It's a set of scripts he created for that workflow.
But to answer your question:
```
git checkout -b myFeature dev
```
Creates the *myFeature* branch off *dev*. Do your work and then
```
git commit -am "Yo... |
4259996 | How can I view a git log of just one user's commits? | 1,724 | 2010-11-23 19:31:42 | <p>When using <code>git log</code>, how can I filter by user so that I see only commits from that user?</p>
| 907,010 | 97,101 | 2022-07-04 15:13:23 | 4,262,780 | 2,372 | 2010-11-24 01:41:29 | 1,864,976 | 2020-07-13 08:22:16 | https://stackoverflow.com/q/4259996 | https://stackoverflow.com/a/4262780 | <p>This works for both <code>git log</code> and <a href="https://git-scm.com/docs/gitk" rel="noreferrer">gitk</a> - the 2 most common ways of viewing history.<br />
You don't need to use the whole name:</p>
<pre><code>git log --author="Jon"
</code></pre>
<p>will match a commit made by "Jonathan Smith&quo... | <p>This works for both <code>git log</code> and <a href="https://git-scm.com/docs/gitk" rel="noreferrer">gitk</a> - the 2 most common ways of viewing history.<br /> You don't need to use the whole name:</p> <pre><code>git log --author="Jon" </code></pre> <p>will match a commit made by "Jonathan Smith&quo... | 119, 456, 47913 | git, git-log, version-control | <h1>How can I view a git log of just one user's commits?</h1>
<p>When using <code>git log</code>, how can I filter by user so that I see only commits from that user?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,823 | git | # How can I view a git log of just one user's commits?
When using `git log`, how can I filter by user so that I see only commits from that user? | This works for both `git log` and [gitk](https://git-scm.com/docs/gitk) - the 2 most common ways of viewing history.
You don't need to use the whole name:
```
git log --author="Jon"
```
will match a commit made by "Jonathan Smith"
```
git log --author=Jon
```
and
```
git log --author=Smith
```
would also work. ... |
492558 | Removing multiple files from a Git repo that have already been deleted from disk | 1,398 | 2009-01-29 17:18:14 | <p>I have a Git repo that I have deleted four files from using <code>rm</code> (<strong>not</strong> <code>git rm</code>), and my Git status looks like this:</p>
<pre><code># deleted: file1.txt
# deleted: file2.txt
# deleted: file3.txt
# deleted: file4.txt
</code></pre>
<p>How do I remove thes... | 573,324 | 12,037 | 2023-01-25 10:57:53 | 1,402,793 | 2,371 | 2009-09-10 00:13:25 | 82,322 | 2014-08-05 15:10:42 | https://stackoverflow.com/q/492558 | https://stackoverflow.com/a/1402793 | <h3>For Git 1.x</h3>
<pre><code>$ git add -u
</code></pre>
<p>This tells git to automatically stage tracked files -- including deleting the previously tracked files. </p>
<h3>For Git 2.0</h3>
<p>To stage your whole working tree:</p>
<pre><code>$ git add -u :/
</code></pre>
<p>To stage just the current path:</p>
... | <h3>For Git 1.x</h3> <pre><code>$ git add -u </code></pre> <p>This tells git to automatically stage tracked files -- including deleting the previously tracked files. </p> <h3>For Git 2.0</h3> <p>To stage your whole working tree:</p> <pre><code>$ git add -u :/ </code></pre> <p>To stage just the current path:</p> ... | 119, 34792, 53850, 112901 | git, git-add, git-commit, git-rm | <h1>Removing multiple files from a Git repo that have already been deleted from disk</h1>
<p>I have a Git repo that I have deleted four files from using <code>rm</code> (<strong>not</strong> <code>git rm</code>), and my Git status looks like this:</p>
<pre><code># deleted: file1.txt
# deleted: file2.txt
# ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,824 | git | # Removing multiple files from a Git repo that have already been deleted from disk
I have a Git repo that I have deleted four files from using `rm` (**not** `git rm`), and my Git status looks like this:
```
# deleted: file1.txt
# deleted: file2.txt
# deleted: file3.txt
# deleted: file4.txt
```... | ### For Git 1.x
```
$ git add -u
```
This tells git to automatically stage tracked files -- including deleting the previously tracked files.
### For Git 2.0
To stage your whole working tree:
```
$ git add -u :/
```
To stage just the current path:
```
$ git add -u .
``` |
307579 | How do I copy a version of a single file from one Git branch to another? | 1,439 | 2008-11-21 01:50:37 | <p>I've got two branches that are fully merged together.</p>
<p>However, after the merge is done, I realise that one file has been messed up by the merge (someone else did an auto-format, gah), and it would just be easier to change to the new version in the other branch, and then reinsert my one line change after bring... | 697,880 | 14,160 | 2024-09-18 08:40:25 | 307,872 | 2,348 | 2008-11-21 04:31:21 | 14,160 | 2021-04-09 16:28:49 | https://stackoverflow.com/q/307579 | https://stackoverflow.com/a/307872 | <p>Run this from the branch where you want the file to end up:</p>
<pre><code>git checkout otherbranch myfile.txt
</code></pre>
<p>General formulas:</p>
<pre><code>git checkout <commit_hash> <relative_path_to_file_or_dir>
git checkout <remote_name>/<branch_name> <file_or_dir>
</code></pre>... | <p>Run this from the branch where you want the file to end up:</p> <pre><code>git checkout otherbranch myfile.txt </code></pre> <p>General formulas:</p> <pre><code>git checkout <commit_hash> <relative_path_to_file_or_dir> git checkout <remote_name>/<branch_name> <file_or_dir> </code></pre>... | 119, 53847, 76220 | branching-and-merging, git, git-branch | <h1>How do I copy a version of a single file from one Git branch to another?</h1>
<p>I've got two branches that are fully merged together.</p>
<p>However, after the merge is done, I realise that one file has been messed up by the merge (someone else did an auto-format, gah), and it would just be easier to change to the... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,825 | git | # How do I copy a version of a single file from one Git branch to another?
I've got two branches that are fully merged together.
However, after the merge is done, I realise that one file has been messed up by the merge (someone else did an auto-format, gah), and it would just be easier to change to the new version in... | Run this from the branch where you want the file to end up:
```
git checkout otherbranch myfile.txt
```
General formulas:
```
git checkout <commit_hash> <relative_path_to_file_or_dir>
git checkout <remote_name>/<branch_name> <file_or_dir>
```
Some notes (from comments):
- Using the commit hash, you can pull files ... |
2016901 | How to list unpushed Git commits (local but not on origin) | 2,360 | 2010-01-06 22:41:15 | <p>How can I view any local commits I've made, that haven't yet been pushed to the remote repository? Occasionally, <code>git status</code> will print out that my branch is X commits ahead of <code>origin/master</code>, but not always.</p>
<p>Is this a bug with my install of Git, or am I missing something?</p>
| 1,628,401 | 52,566 | 2026-01-09 17:56:07 | 2,016,954 | 2,328 | 2010-01-06 22:50:30 | 210,964 | 2022-07-25 03:09:06 | https://stackoverflow.com/q/2016901 | https://stackoverflow.com/a/2016954 | <p>This gives a log of all commits between origin/master and HEAD:</p>
<pre><code>git log origin/master..HEAD
</code></pre>
<p>When HEAD is on the master branch, this gives a log of unpushed commits.</p>
<hr />
<p>Similarly, to view the diff:</p>
<pre><code>git diff origin/master..HEAD
</code></pre>
| <p>This gives a log of all commits between origin/master and HEAD:</p> <pre><code>git log origin/master..HEAD </code></pre> <p>When HEAD is on the master branch, this gives a log of unpushed commits.</p> <hr /> <p>Similarly, to view the diff:</p> <pre><code>git diff origin/master..HEAD </code></pre> | 119, 9033, 47913, 53850 | git, git-commit, git-diff, git-log | <h1>How to list unpushed Git commits (local but not on origin)</h1>
<p>How can I view any local commits I've made, that haven't yet been pushed to the remote repository? Occasionally, <code>git status</code> will print out that my branch is X commits ahead of <code>origin/master</code>, but not always.</p>
<p>Is this ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,826 | git | # How to list unpushed Git commits (local but not on origin)
How can I view any local commits I've made, that haven't yet been pushed to the remote repository? Occasionally, `git status` will print out that my branch is X commits ahead of `origin/master`, but not always.
Is this a bug with my install of Git, or am I ... | This gives a log of all commits between origin/master and HEAD:
```
git log origin/master..HEAD
```
When HEAD is on the master branch, this gives a log of unpushed commits.
---
Similarly, to view the diff:
```
git diff origin/master..HEAD
``` |
226976 | How can I know if a branch has been already merged into master? | 1,512 | 2008-10-22 18:23:03 | <p>I have a git repository with multiple branches.</p>
<p>How can I know which branches are already merged into the main/master branch?</p>
| 500,333 | 14,755 | 2025-11-25 11:11:52 | 227,026 | 2,322 | 2008-10-22 18:33:09 | 14,755 | 2025-11-25 11:11:52 | https://stackoverflow.com/q/226976 | https://stackoverflow.com/a/227026 | <p><code>git branch --merged master</code> lists branches merged into <em>master</em></p>
<p><code>git branch --merged</code> lists branches merged into <em>HEAD</em> (i.e. tip of current branch)</p>
<p><code>git branch --no-merged</code> lists branches that have not been merged</p>
<p>By default this applies to only t... | <p><code>git branch --merged master</code> lists branches merged into <em>master</em></p> <p><code>git branch --merged</code> lists branches merged into <em>HEAD</em> (i.e. tip of current branch)</p> <p><code>git branch --no-merged</code> lists branches that have not been merged</p> <p>By default this applies to only t... | 119 | git | <h1>How can I know if a branch has been already merged into master?</h1>
<p>I have a git repository with multiple branches.</p>
<p>How can I know which branches are already merged into the main/master branch?</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,827 | git | # How can I know if a branch has been already merged into master?
I have a git repository with multiple branches.
How can I know which branches are already merged into the main/master branch? | `git branch --merged master` lists branches merged into *master*
`git branch --merged` lists branches merged into *HEAD* (i.e. tip of current branch)
`git branch --no-merged` lists branches that have not been merged
By default this applies to only the local branches. The `-a` flag will show both local and remote bra... |
5834014 | LF will be replaced by CRLF in git - What is that and is it important? | 1,862 | 2011-04-29 15:28:10 | <pre><code>git init
git add .
</code></pre>
<p>Gives the following warnings for many files:</p>
<blockquote>
<p>The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in <filename>.</p>
</blockquote>
<p>What's the difference between LF and CRLF? What should I ... | 2,117,687 | 604,023 | 2022-07-17 05:07:18 | 5,834,094 | 2,315 | 2011-04-29 15:34:23 | 109,000 | 2019-10-11 17:46:23 | https://stackoverflow.com/q/5834014 | https://stackoverflow.com/a/5834094 | <p>In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.</p>
<p>If you are a single developer working on a windows ... | <p>In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.</p> <p>If you are a single developer working on a windows ... | 119, 3705, 47852 | git, linefeed, newline | <h1>LF will be replaced by CRLF in git - What is that and is it important?</h1>
<pre><code>git init
git add .
</code></pre>
<p>Gives the following warnings for many files:</p>
<blockquote>
<p>The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in <filename>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,828 | git | # LF will be replaced by CRLF in git - What is that and is it important?
```
git init
git add .
```
Gives the following warnings for many files:
> The file will have its original line endings in your working directory.
> warning: LF will be replaced by CRLF in <filename>.
What's the difference between LF and CRLF? ... | In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). when you get code from git that was uploaded from a unix system they will only have an LF.
If you are a single developer working on a windows machine, a... |
7099833 | How do I revert a merge commit that has already been pushed to remote? | 1,896 | 2011-08-17 21:37:28 | <p><code>git revert <commit_hash></code> alone won't work. Apparently, <code>-m</code> must be specified.</p>
| 1,960,100 | 708,854 | 2025-06-20 03:41:03 | 7,100,005 | 2,284 | 2011-08-17 21:53:14 | 189,179 | 2025-06-20 03:41:03 | https://stackoverflow.com/q/7099833 | https://stackoverflow.com/a/7100005 | <p>In <code>git revert -m</code>, the <code>-m</code> option specifies the <strong>parent number</strong>. This is needed because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.</p>
<p>When you view a merge... | <p>In <code>git revert -m</code>, the <code>-m</code> option specifies the <strong>parent number</strong>. This is needed because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.</p> <p>When you view a merge... | 119 | git | <h1>How do I revert a merge commit that has already been pushed to remote?</h1>
<p><code>git revert <commit_hash></code> alone won't work. Apparently, <code>-m</code> must be specified.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,829 | git | # How do I revert a merge commit that has already been pushed to remote?
`git revert <commit_hash>` alone won't work. Apparently, `-m` must be specified. | In `git revert -m`, the `-m` option specifies the **parent number**. This is needed because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.
When you view a merge commit in the output of `git log`, you will... |
7726949 | Remove tracking branches no longer on remote | 2,360 | 2011-10-11 13:37:35 | <p>Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?</p>
<p>Example:</p>
<p>Branches (local and remote)</p>
<ul>
<li>master</li>
<li>origin/master</li>
<li>origin/bug-fix-a</li>
<li>origin/bug-fix-b</li>
<li>origin/bug-fix-c</li>
</ul>
<p>Locally, I only have a master b... | 1,226,893 | 133,986 | 2025-08-11 08:13:00 | 28,464,339 | 2,263 | 2015-02-11 20:56:18 | 1,436,129 | 2020-02-26 14:22:22 | https://stackoverflow.com/q/7726949 | https://stackoverflow.com/a/28464339 | <p><code>git remote prune origin</code> prunes tracking branches not on the remote.</p>
<p><code>git branch --merged</code> lists branches that have been merged into the current branch.</p>
<p><code>xargs git branch -d</code> deletes branches listed on standard input.</p>
<p>Be careful deleting branches listed by <c... | <p><code>git remote prune origin</code> prunes tracking branches not on the remote.</p> <p><code>git branch --merged</code> lists branches that have been merged into the current branch.</p> <p><code>xargs git branch -d</code> deletes branches listed on standard input.</p> <p>Be careful deleting branches listed by <c... | 119, 76220 | git, git-branch | <h1>Remove tracking branches no longer on remote</h1>
<p>Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?</p>
<p>Example:</p>
<p>Branches (local and remote)</p>
<ul>
<li>master</li>
<li>origin/master</li>
<li>origin/bug-fix-a</li>
<li>origin/bug-fix-b</li>
<li>origin/bu... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,830 | git | # Remove tracking branches no longer on remote
Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?
Example:
Branches (local and remote)
- master
- origin/master
- origin/bug-fix-a
- origin/bug-fix-b
- origin/bug-fix-c
Locally, I only have a master branch. Now I need to w... | `git remote prune origin` prunes tracking branches not on the remote.
`git branch --merged` lists branches that have been merged into the current branch.
`xargs git branch -d` deletes branches listed on standard input.
Be careful deleting branches listed by `git branch --merged`. The list could include `master` or o... |
7860751 | Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists | 1,089 | 2011-10-22 16:03:54 | <p>I am still getting this error message, when I try to move my project tree on to git repo.</p>
<p>I checked the permissions of my directory with this project and these are set on 777. In terminal in the directory with <code>my_project</code> I set:</p>
<p><code>git init</code></p>
<p>and then if I try</p>
<p><code>gi... | 873,757 | 984,621 | 2025-03-26 10:35:08 | 7,860,765 | 2,255 | 2011-10-22 16:06:16 | 392,858 | 2016-08-18 16:19:48 | https://stackoverflow.com/q/7860751 | https://stackoverflow.com/a/7860765 | <p>Try</p>
<pre><code>rm -f ./.git/index.lock
</code></pre>
<p>In your repository directory. The error message is rather explicit as to what causes it typically, so if you have no other git processes running (which is the normal case), go ahead and delete that file.</p>
| <p>Try</p> <pre><code>rm -f ./.git/index.lock </code></pre> <p>In your repository directory. The error message is rather explicit as to what causes it typically, so if you have no other git processes running (which is the normal case), go ahead and delete that file.</p> | 119 | git | <h1>Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists</h1>
<p>I am still getting this error message, when I try to move my project tree on to git repo.</p>
<p>I checked the permissions of my directory with this project and these are set on 777. In terminal in the directory with <code>my_proj... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,831 | git | # Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists
I am still getting this error message, when I try to move my project tree on to git repo.
I checked the permissions of my directory with this project and these are set on 777. In terminal in the directory with `my_project` I set:
`git in... | Try
```
rm -f ./.git/index.lock
```
In your repository directory. The error message is rather explicit as to what causes it typically, so if you have no other git processes running (which is the normal case), go ahead and delete that file. |
1463340 | How can I revert multiple Git commits? | 1,780 | 2009-09-23 00:27:14 | <p>I have a Git repository that looks like this:</p>
<pre><code>A <- B <- C <- D <- HEAD
</code></pre>
<p>I want the head of the branch to point to A, i.e., I want B, C, D, and HEAD to disappear and I want head to be synonymous with A.</p>
<p>It sounds like I can either try to rebase (doesn't apply, since I... | 1,408,702 | 126,855 | 2024-06-29 06:04:03 | 1,470,452 | 2,236 | 2009-09-24 08:44:40 | 46,058 | 2020-10-12 17:20:57 | https://stackoverflow.com/q/1463340 | https://stackoverflow.com/a/1470452 | <p><em>Expanding what I wrote in a comment</em></p>
<p>The general rule is that you should not rewrite (change) history that you have published, because somebody might have based their work on it. If you rewrite (change) history, you would make problems with merging their changes and with updating for them.</p>
<p>So ... | <p><em>Expanding what I wrote in a comment</em></p> <p>The general rule is that you should not rewrite (change) history that you have published, because somebody might have based their work on it. If you rewrite (change) history, you would make problems with merging their changes and with updating for them.</p> <p>So ... | 119, 5597, 34403 | commit, git, git-revert | <h1>How can I revert multiple Git commits?</h1>
<p>I have a Git repository that looks like this:</p>
<pre><code>A <- B <- C <- D <- HEAD
</code></pre>
<p>I want the head of the branch to point to A, i.e., I want B, C, D, and HEAD to disappear and I want head to be synonymous with A.</p>
<p>It sounds like I ... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,834 | git | # How can I revert multiple Git commits?
I have a Git repository that looks like this:
```
A <- B <- C <- D <- HEAD
```
I want the head of the branch to point to A, i.e., I want B, C, D, and HEAD to disappear and I want head to be synonymous with A.
It sounds like I can either try to rebase (doesn't apply, since I'... | *Expanding what I wrote in a comment*
The general rule is that you should not rewrite (change) history that you have published, because somebody might have based their work on it. If you rewrite (change) history, you would make problems with merging their changes and with updating for them.
So the solution is to crea... |
1505948 | How do I remove a single file from the staging area (undo git add)? | 1,476 | 2009-10-01 19:24:04 | <p><strong>Situation:</strong> I have a Git repository with files already in the index. I make changes to several files, open Git and add these files to my staging area with "git add ."</p>
<p><strong>Question:</strong> How do I remove one of those files from the staging area but not remove it from the index or undo ... | 885,543 | 27,025 | 2024-05-16 09:07:16 | 1,505,968 | 2,206 | 2009-10-01 19:29:08 | 63,147 | 2024-05-16 09:07:16 | https://stackoverflow.com/q/1505948 | https://stackoverflow.com/a/1505968 | <p>If I understand the question correctly, you simply want to "undo" the <code>git add</code> that was done for that file.</p>
<p>If you need to remove a <strong>single file</strong> from the staging area, use</p>
<p><code>git reset HEAD -- <file></code></p>
<p>If you need to remove a <strong>whole dire... | <p>If I understand the question correctly, you simply want to "undo" the <code>git add</code> that was done for that file.</p> <p>If you need to remove a <strong>single file</strong> from the staging area, use</p> <p><code>git reset HEAD -- <file></code></p> <p>If you need to remove a <strong>whole dire... | 119, 456, 20002 | git, staging, version-control | <h1>How do I remove a single file from the staging area (undo git add)?</h1>
<p><strong>Situation:</strong> I have a Git repository with files already in the index. I make changes to several files, open Git and add these files to my staging area with "git add ."</p>
<p><strong>Question:</strong> How do I remove one o... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,835 | git | # How do I remove a single file from the staging area (undo git add)?
**Situation:** I have a Git repository with files already in the index. I make changes to several files, open Git and add these files to my staging area with "git add ."
**Question:** How do I remove one of those files from the staging area but not... | If I understand the question correctly, you simply want to "undo" the `git add` that was done for that file.
If you need to remove a **single file** from the staging area, use
`git reset HEAD -- <file>`
If you need to remove a **whole directory (folder)** from the staging area, use
`git reset HEAD -- <directoryName... |
1470572 | Ignoring any 'bin' directory on a git project | 1,495 | 2009-09-24 09:13:51 | <p>I have a directory structure like this:</p>
<pre><code>.git/
.gitignore
main/
...
tools/
...
...
</code></pre>
<p>Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore everything under it too). I've tried each of these patterns ... | 1,116,305 | 40,834 | 2024-11-22 00:57:37 | 1,470,664 | 2,178 | 2009-09-24 09:35:38 | 19,563 | 2023-08-30 13:46:14 | https://stackoverflow.com/q/1470572 | https://stackoverflow.com/a/1470664 | <p>Before version 1.8.2, <code>**</code> didn't have any special meaning in the <code>.gitignore</code>. As of 1.8.2 git supports <code>**</code> to mean zero or more sub-directories (see <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.2.txt" rel="noreferrer">release notes</a>).</p>
<p>The wa... | <p>Before version 1.8.2, <code>**</code> didn't have any special meaning in the <code>.gitignore</code>. As of 1.8.2 git supports <code>**</code> to mean zero or more sub-directories (see <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.2.txt" rel="noreferrer">release notes</a>).</p> <p>The wa... | 119, 25056 | git, gitignore | <h1>Ignoring any 'bin' directory on a git project</h1>
<p>I have a directory structure like this:</p>
<pre><code>.git/
.gitignore
main/
...
tools/
...
...
</code></pre>
<p>Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore every... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,836 | git | # Ignoring any 'bin' directory on a git project
I have a directory structure like this:
```
.git/
.gitignore
main/
...
tools/
...
...
```
Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore everything under it too). I've tried... | Before version 1.8.2, `**` didn't have any special meaning in the `.gitignore`. As of 1.8.2 git supports `**` to mean zero or more sub-directories (see [release notes](https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.2.txt)).
The way to ignore *all* directories called `bin` anywhere below the current ... |
7335420 | Global Git ignore | 1,381 | 2011-09-07 14:16:11 | <p>I want to set up Git to globally ignore certain files.</p>
<p>I have added a <code>.gitignore</code> file to my home directory (<code>/Users/me/</code>) and I have added the following line to it:</p>
<pre><code>*.tmproj
</code></pre>
<p>But it is not ignoring this type of files, any idea what I am doing wrong?</p... | 675,541 | 445,126 | 2025-08-15 16:48:35 | 7,335,487 | 2,175 | 2011-09-07 14:21:09 | 19,563 | 2022-05-03 14:39:47 | https://stackoverflow.com/q/7335420 | https://stackoverflow.com/a/7335487 | <p>You need to set up your global <code>core.excludesfile</code> configuration file to point to this global ignore file e.g:</p>
<p>*<strong>nix or Windows git bash:</strong></p>
<pre><code>git config --global core.excludesFile '~/.gitignore'
</code></pre>
<p><strong>Windows cmd:</strong></p>
<pre><code>git config --gl... | <p>You need to set up your global <code>core.excludesfile</code> configuration file to point to this global ignore file e.g:</p> <p>*<strong>nix or Windows git bash:</strong></p> <pre><code>git config --global core.excludesFile '~/.gitignore' </code></pre> <p><strong>Windows cmd:</strong></p> <pre><code>git config --gl... | 119, 3881, 25056 | git, gitignore, global | <h1>Global Git ignore</h1>
<p>I want to set up Git to globally ignore certain files.</p>
<p>I have added a <code>.gitignore</code> file to my home directory (<code>/Users/me/</code>) and I have added the following line to it:</p>
<pre><code>*.tmproj
</code></pre>
<p>But it is not ignoring this type of files, any ide... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,837 | git | # Global Git ignore
I want to set up Git to globally ignore certain files.
I have added a `.gitignore` file to my home directory (`/Users/me/`) and I have added the following line to it:
```
*.tmproj
```
But it is not ignoring this type of files, any idea what I am doing wrong? | You need to set up your global `core.excludesfile` configuration file to point to this global ignore file e.g:
***nix or Windows git bash:**
```
git config --global core.excludesFile '~/.gitignore'
```
**Windows cmd:**
```
git config --global core.excludesFile "%USERPROFILE%\.gitignore"
```
**Windows PowerShell:**... |
13148066 | Warning: push.default is unset; its implicit value is changing in Git 2.0 | 1,667 | 2012-10-30 21:48:16 | <p>I've been using Git for a while now and have recently downloaded an update only to find this warning message come up when I try to <code>push</code>.</p>
<pre><code>warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the curre... | 260,505 | 333,255 | 2020-09-15 13:30:20 | 13,148,313 | 2,172 | 2012-10-30 22:11:49 | 98,117 | 2017-09-08 17:48:07 | https://stackoverflow.com/q/13148066 | https://stackoverflow.com/a/13148313 | <p>It's explained in great detail in <a href="https://git-scm.com/docs/git-config.html#git-config-pushdefault" rel="noreferrer">the docs</a>, but I'll try to summarize:</p>
<ul>
<li><p><code>matching</code> means <code>git push</code> will <strong>push all your local branches</strong> to the ones with the same name on... | <p>It's explained in great detail in <a href="https://git-scm.com/docs/git-config.html#git-config-pushdefault" rel="noreferrer">the docs</a>, but I'll try to summarize:</p> <ul> <li><p><code>matching</code> means <code>git push</code> will <strong>push all your local branches</strong> to the ones with the same name on... | 119, 456, 28898 | git, git-push, version-control | <h1>Warning: push.default is unset; its implicit value is changing in Git 2.0</h1>
<p>I've been using Git for a while now and have recently downloaded an update only to find this warning message come up when I try to <code>push</code>.</p>
<pre><code>warning: push.default is unset; its implicit value is changing in
G... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,838 | git | # Warning: push.default is unset; its implicit value is changing in Git 2.0
I've been using Git for a while now and have recently downloaded an update only to find this warning message come up when I try to `push`.
```
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simp... | It's explained in great detail in [the docs](https://git-scm.com/docs/git-config.html#git-config-pushdefault), but I'll try to summarize:
- `matching` means `git push` will **push all your local branches** to the ones with the same name on the remote. This makes it easy to accidentally push a branch you didn't intend ... |
3528245 | What's the difference between git reset --mixed, --soft, and --hard? | 1,233 | 2010-08-20 04:41:20 | <p>I'm looking to split a commit up and not sure which reset option to use.</p>
<p>I was looking at the page <a href="https://stackoverflow.com/questions/2530060/can-you-explain-to-me-git-reset-in-plain-english">In plain English, what does "git reset" do?</a>, but I realized I don't really understand what th... | 470,826 | 333,841 | 2025-02-07 14:22:42 | 3,528,483 | 2,172 | 2010-08-20 05:53:19 | 369,986 | 2024-03-22 18:40:39 | https://stackoverflow.com/q/3528245 | https://stackoverflow.com/a/3528483 | <p>When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using <code>git add</code>. When you make a commit, the changes that are committed are those that have been added to the index.<sup>1</sup></p>
<p><code>git reset</code> ... | <p>When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using <code>git add</code>. When you make a commit, the changes that are committed are those that have been added to the index.<sup>1</sup></p> <p><code>git reset</code> ... | 119, 456 | git, version-control | <h1>What's the difference between git reset --mixed, --soft, and --hard?</h1>
<p>I'm looking to split a commit up and not sure which reset option to use.</p>
<p>I was looking at the page <a href="https://stackoverflow.com/questions/2530060/can-you-explain-to-me-git-reset-in-plain-english">In plain English, what does &... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,839 | git | # What's the difference between git reset --mixed, --soft, and --hard?
I'm looking to split a commit up and not sure which reset option to use.
I was looking at the page [In plain English, what does "git reset" do?](https://stackoverflow.com/questions/2530060/can-you-explain-to-me-git-reset-in-plain-english), but I r... | When you modify a file in your repository, the change is initially unstaged. In order to commit it, you must stage it—that is, add it to the index—using `git add`. When you make a commit, the changes that are committed are those that have been added to the index.1
`git reset` changes, at minimum, where the current bra... |
8981194 | Changing git commit message after push (given that no one pulled from remote) | 1,762 | 2012-01-24 01:58:25 | <p>I have made a git commit and subsequent push. I would like to change the commit message. If I understand correctly, this is not advisable because someone might have pulled from the remote repository before I make such changes. What if I know that no one has pulled? </p>
<p>Is there a way to do this?</p>
| 1,418,303 | 257,065 | 2025-03-05 10:18:36 | 8,981,216 | 2,139 | 2012-01-24 02:02:24 | 82,294 | 2016-02-12 22:18:07 | https://stackoverflow.com/q/8981194 | https://stackoverflow.com/a/8981216 | <h3>Changing history</h3>
<p>If it is the most recent commit, you can simply do this:</p>
<pre><code>git commit --amend
</code></pre>
<p>This brings up the editor with the last commit message and lets you edit the message. (You can use <code>-m</code> if you want to wipe out the old message and use a new one.)</p>
... | <h3>Changing history</h3> <p>If it is the most recent commit, you can simply do this:</p> <pre><code>git commit --amend </code></pre> <p>This brings up the editor with the last commit message and lets you edit the message. (You can use <code>-m</code> if you want to wipe out the old message and use a new one.)</p> ... | 119, 4236, 5597 | commit, git, push | <h1>Changing git commit message after push (given that no one pulled from remote)</h1>
<p>I have made a git commit and subsequent push. I would like to change the commit message. If I understand correctly, this is not advisable because someone might have pulled from the remote repository before I make such changes. Wha... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,841 | git | # Changing git commit message after push (given that no one pulled from remote)
I have made a git commit and subsequent push. I would like to change the commit message. If I understand correctly, this is not advisable because someone might have pulled from the remote repository before I make such changes. What if I kn... | ### Changing history
If it is the most recent commit, you can simply do this:
```
git commit --amend
```
This brings up the editor with the last commit message and lets you edit the message. (You can use `-m` if you want to wipe out the old message and use a new one.)
### Pushing
And then when you push, do this:
... |
6089294 | How can I avoid having to do "git branch --set-upstream", and instead default to automatically setup remote tracking? | 2,078 | 2011-05-22 16:39:49 | <p>I create a new branch in Git:</p>
<pre class="lang-none prettyprint-override"><code>git branch my_branch
</code></pre>
<p>Push it:</p>
<pre class="lang-none prettyprint-override"><code>git push origin my_branch
</code></pre>
<p>Now say someone made some changes on the server and I want to pull from <code>origin/my_b... | 1,440,798 | 76,701 | 2025-12-15 21:51:17 | 6,089,415 | 2,121 | 2011-05-22 16:58:56 | 223,092 | 2025-10-27 15:34:54 | https://stackoverflow.com/q/6089294 | https://stackoverflow.com/a/6089415 | <h3>Git v2.37.1 and above</h3>
<p>If you are using the mentioned version or above you can use this new config entry to automatically setup remote tracking:</p>
<pre class="lang-none prettyprint-override"><code>git config --global push.autoSetupRemote true
</code></pre>
<p>After that, when you do <code>git push</code> t... | <h3>Git v2.37.1 and above</h3> <p>If you are using the mentioned version or above you can use this new config entry to automatically setup remote tracking:</p> <pre class="lang-none prettyprint-override"><code>git config --global push.autoSetupRemote true </code></pre> <p>After that, when you do <code>git push</code> t... | 119, 76220 | git, git-branch | <h1>How can I avoid having to do "git branch --set-upstream", and instead default to automatically setup remote tracking?</h1>
<p>I create a new branch in Git:</p>
<pre class="lang-none prettyprint-override"><code>git branch my_branch
</code></pre>
<p>Push it:</p>
<pre class="lang-none prettyprint-override"><code>git p... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,842 | git | # How can I avoid having to do "git branch --set-upstream", and instead default to automatically setup remote tracking?
I create a new branch in Git:
```
git branch my_branch
```
Push it:
```
git push origin my_branch
```
Now say someone made some changes on the server and I want to pull from `origin/my_branch`. I... | ### Git v2.37.1 and above
If you are using the mentioned version or above you can use this new config entry to automatically setup remote tracking:
```
git config --global push.autoSetupRemote true
```
After that, when you do `git push` tracking is setup automatically. No need for `git push -u origin my_branch`
---... |
1223354 | Undo Git pull. How to bring repositories to the old state | 1,497 | 2009-08-03 16:42:51 | <p>Is there a way to revert or undo Git pull, so that my source/repositories will come to the old state that was before doing Git pull?</p>
<p>I want to do this, because it merged some files which I didn't want to do so, but only merge other remaining files. So, I want to get those files back. Is that possible?</p>
<p>... | 2,031,809 | 142,312 | 2025-09-11 08:57:32 | 1,223,385 | 2,119 | 2009-08-03 16:47:27 | 912 | 2019-09-20 19:51:36 | https://stackoverflow.com/q/1223354 | https://stackoverflow.com/a/1223385 | <p>Running <code>git pull</code> performs the following tasks, in order:</p>
<ol>
<li><code>git fetch</code> </li>
<li><code>git merge</code></li>
</ol>
<p>The merge step combines branches that have been setup to be merged in your config. You want to undo the <strong>merge</strong> step, but probably not the <strong>... | <p>Running <code>git pull</code> performs the following tasks, in order:</p> <ol> <li><code>git fetch</code> </li> <li><code>git merge</code></li> </ol> <p>The merge step combines branches that have been setup to be merged in your config. You want to undo the <strong>merge</strong> step, but probably not the <strong>... | 119, 456, 28897 | git, git-merge, version-control | <h1>Undo Git pull. How to bring repositories to the old state</h1>
<p>Is there a way to revert or undo Git pull, so that my source/repositories will come to the old state that was before doing Git pull?</p>
<p>I want to do this, because it merged some files which I didn't want to do so, but only merge other remaining f... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,843 | git | # Undo Git pull. How to bring repositories to the old state
Is there a way to revert or undo Git pull, so that my source/repositories will come to the old state that was before doing Git pull?
I want to do this, because it merged some files which I didn't want to do so, but only merge other remaining files. So, I wan... | Running `git pull` performs the following tasks, in order:
1. `git fetch`
2. `git merge`
The merge step combines branches that have been setup to be merged in your config. You want to undo the **merge** step, but probably not the **fetch** (doesn't make a lot of sense and shouldn't be necessary).
To undo the **merge... |
1213430 | How can I fully delete a Git repository created with init? | 1,699 | 2009-07-31 16:06:20 | <p>I created a Git repository with <code>git init</code>. I'd like to delete it entirely and initialise a new one.</p>
| 1,931,541 | 105,813 | 2025-09-21 07:33:27 | 1,213,446 | 2,094 | 2009-07-31 16:08:35 | 1,466 | 2024-11-01 16:05:39 | https://stackoverflow.com/q/1213430 | https://stackoverflow.com/a/1213446 | <p>Git keeps all of its files in the <em>.git</em> directory. Just remove that one and initialise again.</p>
<p>If you can't find it, it's because it is hidden.</p>
<ul>
<li><p>In <a href="https://en.wikipedia.org/wiki/Windows_7" rel="noreferrer">Windows 7</a>, you need to go to your folder, click on <em>Organize</em> ... | <p>Git keeps all of its files in the <em>.git</em> directory. Just remove that one and initialise again.</p> <p>If you can't find it, it's because it is hidden.</p> <ul> <li><p>In <a href="https://en.wikipedia.org/wiki/Windows_7" rel="noreferrer">Windows 7</a>, you need to go to your folder, click on <em>Organize</em> ... | 119, 106207 | git, git-init | <h1>How can I fully delete a Git repository created with init?</h1>
<p>I created a Git repository with <code>git init</code>. I'd like to delete it entirely and initialise a new one.</p>
| q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,844 | git | # How can I fully delete a Git repository created with init?
I created a Git repository with `git init`. I'd like to delete it entirely and initialise a new one. | Git keeps all of its files in the *.git* directory. Just remove that one and initialise again.
If you can't find it, it's because it is hidden.
- In [Windows 7](https://en.wikipedia.org/wiki/Windows_7), you need to go to your folder, click on *Organize* on the top left, then click on *Folder and search options*, then... |
4404172 | How to tag an older commit in Git? | 1,396 | 2010-12-09 23:23:16 | <p>We are new to Git, and I want to set a tag at the beginning of our repository.
Our production code is the same as the beginning repository, but we've made commits since then.
A tag at the beginning would allow us to "roll back" production to a known, stable state.</p>
<p>So how to add a tag to an arbitrary... | 545,391 | 509,856 | 2024-02-01 00:07:00 | 4,404,197 | 2,058 | 2010-12-09 23:27:28 | 256,854 | 2019-06-16 20:32:01 | https://stackoverflow.com/q/4404172 | https://stackoverflow.com/a/4404197 | <p>Example:</p>
<pre><code>git tag -a v1.2 9fceb02 -m "Message here"
</code></pre>
<p>Where <code>9fceb02</code> is the beginning part of the commit id.</p>
<p>You can then push the tag using <code>git push origin v1.2</code>.</p>
<p>You can do <code>git log</code> to show all the commit id's in your current branch... | <p>Example:</p> <pre><code>git tag -a v1.2 9fceb02 -m "Message here" </code></pre> <p>Where <code>9fceb02</code> is the beginning part of the commit id.</p> <p>You can then push the tag using <code>git push origin v1.2</code>.</p> <p>You can do <code>git log</code> to show all the commit id's in your current branch... | 119, 456, 60718 | git, git-tag, version-control | <h1>How to tag an older commit in Git?</h1>
<p>We are new to Git, and I want to set a tag at the beginning of our repository.
Our production code is the same as the beginning repository, but we've made commits since then.
A tag at the beginning would allow us to "roll back" production to a known, stable state... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,845 | git | # How to tag an older commit in Git?
We are new to Git, and I want to set a tag at the beginning of our repository.
Our production code is the same as the beginning repository, but we've made commits since then.
A tag at the beginning would allow us to "roll back" production to a known, stable state.
So how to add a ... | Example:
```
git tag -a v1.2 9fceb02 -m "Message here"
```
Where `9fceb02` is the beginning part of the commit id.
You can then push the tag using `git push origin v1.2`.
You can do `git log` to show all the commit id's in your current branch.
There is also a good chapter on [tagging](http://git-scm.com/book/en/Gi... |
9483757 | How to exit git log or git diff | 1,355 | 2012-02-28 14:30:17 | <p>I'm trying to learn Git with the help of <a href="http://gitimmersion.com/" rel="noreferrer">Git Immersion</a>.<br>
There's one thing that frustrates me whenever I use <code>git log</code> or <code>git diff</code>:</p>
<p><img src="https://i.sstatic.net/yJ0Ms.png" alt="Git log shows (END) marker"></p>
<p>I can't f... | 683,366 | 472,034 | 2025-09-20 21:13:50 | 9,483,803 | 2,058 | 2012-02-28 14:33:13 | 166,749 | 2013-08-14 07:21:09 | https://stackoverflow.com/q/9483757 | https://stackoverflow.com/a/9483803 | <p>You're in the <code>less</code> program, which makes the output of <code>git log</code> scrollable.</p>
<p>Type <kbd>q</kbd> to exit this screen. Type <kbd>h</kbd> to get help.</p>
<p>If you don't want to read the output in a pager and want it to be just printed to the terminal define the environment variable <cod... | <p>You're in the <code>less</code> program, which makes the output of <code>git log</code> scrollable.</p> <p>Type <kbd>q</kbd> to exit this screen. Type <kbd>h</kbd> to get help.</p> <p>If you don't want to read the output in a pager and want it to be just printed to the terminal define the environment variable <cod... | 119, 9033, 47913 | git, git-diff, git-log | <h1>How to exit git log or git diff</h1>
<p>I'm trying to learn Git with the help of <a href="http://gitimmersion.com/" rel="noreferrer">Git Immersion</a>.<br>
There's one thing that frustrates me whenever I use <code>git log</code> or <code>git diff</code>:</p>
<p><img src="https://i.sstatic.net/yJ0Ms.png" alt="Git l... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,846 | git | # How to exit git log or git diff
I'm trying to learn Git with the help of [Git Immersion](http://gitimmersion.com/).
There's one thing that frustrates me whenever I use `git log` or `git diff`:

I can't figure out what to do next when I encounter this ... | You're in the `less` program, which makes the output of `git log` scrollable.
Type `q` to exit this screen. Type `h` to get help.
If you don't want to read the output in a pager and want it to be just printed to the terminal define the environment variable `GIT_PAGER` to `cat` or set `core.pager` to `cat` (execute `g... |
11183788 | In a Git repository, how to properly rename a directory? | 1,087 | 2012-06-25 05:15:06 | <p>I think it should work to copy the directory to be renamed to a new directory with desired name, and <a href="https://stackoverflow.com/questions/1947430/git-remove-directory">delete the old directory</a>, and <code>git add</code>, <code>git commit</code> and <code>push</code> everything. But is this the best way?... | 766,834 | 1,150,778 | 2024-11-21 10:29:23 | 11,183,844 | 2,043 | 2012-06-25 05:22:38 | 19,563 | 2016-12-31 22:54:22 | https://stackoverflow.com/q/11183788 | https://stackoverflow.com/a/11183844 | <p>Basic rename (or move):</p>
<pre><code>git mv <old name> <new name>
</code></pre>
<p>Case sensitive rename—eg. from <code>casesensitive</code> to <code>CaseSensitive</code>—you must use a two step:</p>
<pre><code>git mv casesensitive tmp
git mv tmp CaseSensitive
</code></pre>
<p>(<a href="https://sta... | <p>Basic rename (or move):</p> <pre><code>git mv <old name> <new name> </code></pre> <p>Case sensitive rename—eg. from <code>casesensitive</code> to <code>CaseSensitive</code>—you must use a two step:</p> <pre><code>git mv casesensitive tmp git mv tmp CaseSensitive </code></pre> <p>(<a href="https://sta... | 119, 218, 4510 | directory, git, rename | <h1>In a Git repository, how to properly rename a directory?</h1>
<p>I think it should work to copy the directory to be renamed to a new directory with desired name, and <a href="https://stackoverflow.com/questions/1947430/git-remove-directory">delete the old directory</a>, and <code>git add</code>, <code>git commit</... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,847 | git | # In a Git repository, how to properly rename a directory?
I think it should work to copy the directory to be renamed to a new directory with desired name, and [delete the old directory](https://stackoverflow.com/questions/1947430/git-remove-directory), and `git add`, `git commit` and `push` everything. But is this th... | Basic rename (or move):
```
git mv <old name> <new name>
```
Case sensitive rename—eg. from `casesensitive` to `CaseSensitive`—you must use a two step:
```
git mv casesensitive tmp
git mv tmp CaseSensitive
```
([More about case sensitivity in Git…](https://stackoverflow.com/a/17688308/101290))
…followed by commit ... |
9210446 | How can I replace a local branch with a remote branch entirely in Git? | 1,315 | 2012-02-09 11:59:28 | <p>I have two branches:</p>
<ol>
<li>local branch (the one which I work with)</li>
<li>remote branch (public, only well-tested commits go there)</li>
</ol>
<p>Recently I seriously messed up my local branch.</p>
<p>How would I replace the local branch entirely with the remote one, so I can continue my work from where th... | 896,665 | 1,151,658 | 2025-05-30 14:04:56 | 9,210,705 | 2,033 | 2012-02-09 12:19:20 | 85,134 | 2018-01-29 00:35:47 | https://stackoverflow.com/q/9210446 | https://stackoverflow.com/a/9210705 | <ol>
<li>Make sure you've checked out the branch you're replacing (from Zoltán's <a href="https://stackoverflow.com/questions/9210446/replace-local-branch-with-remote-branch-entirely#comment64191505_9210705">comment</a>).</li>
<li><p>Assuming that master is the local branch you're replacing, and that "origin/master" is... | <ol> <li>Make sure you've checked out the branch you're replacing (from Zoltán's <a href="https://stackoverflow.com/questions/9210446/replace-local-branch-with-remote-branch-entirely#comment64191505_9210705">comment</a>).</li> <li><p>Assuming that master is the local branch you're replacing, and that "origin/master" is... | 119 | git | <h1>How can I replace a local branch with a remote branch entirely in Git?</h1>
<p>I have two branches:</p>
<ol>
<li>local branch (the one which I work with)</li>
<li>remote branch (public, only well-tested commits go there)</li>
</ol>
<p>Recently I seriously messed up my local branch.</p>
<p>How would I replace the lo... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,848 | git | # How can I replace a local branch with a remote branch entirely in Git?
I have two branches:
1. local branch (the one which I work with)
2. remote branch (public, only well-tested commits go there)
Recently I seriously messed up my local branch.
How would I replace the local branch entirely with the remote one, so... | 1. Make sure you've checked out the branch you're replacing (from Zoltán's [comment](https://stackoverflow.com/questions/9210446/replace-local-branch-with-remote-branch-entirely#comment64191505_9210705)).
2. Assuming that master is the local branch you're replacing, and that "origin/master" is the remote branch you wan... |
1090309 | git: undo all working dir changes including new files | 1,397 | 2009-07-07 04:07:40 | <p>How to delete all changes from working directory including new untracked files. I know that <code>git checkout -f</code> does that, but it doesn't delete new untracked files created since last commit.</p>
<p>Does anybody have an idea how to do that?</p>
| 936,931 | 76,146 | 2025-01-10 08:45:53 | 1,090,316 | 2,017 | 2009-07-07 04:09:19 | null | 2018-10-08 09:42:54 | https://stackoverflow.com/q/1090309 | https://stackoverflow.com/a/1090316 | <pre><code>git reset --hard # removes staged and working directory changes
## !! be very careful with these !!
## you may end up deleting what you don't want to
## read comments and manual.
git clean -f -d # remove untracked
git clean -f -x -d # CAUTION: as above but removes ignored files like config.
git clean -fxd :... | <pre><code>git reset --hard # removes staged and working directory changes ## !! be very careful with these !! ## you may end up deleting what you don't want to ## read comments and manual. git clean -f -d # remove untracked git clean -f -x -d # CAUTION: as above but removes ignored files like config. git clean -fxd :... | 119 | git | <h1>git: undo all working dir changes including new files</h1>
<p>How to delete all changes from working directory including new untracked files. I know that <code>git checkout -f</code> does that, but it doesn't delete new untracked files created since last commit.</p>
<p>Does anybody have an idea how to do that?</p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,849 | git | # git: undo all working dir changes including new files
How to delete all changes from working directory including new untracked files. I know that `git checkout -f` does that, but it doesn't delete new untracked files created since last commit.
Does anybody have an idea how to do that? | ```
git reset --hard # removes staged and working directory changes
## !! be very careful with these !!
## you may end up deleting what you don't want to
## read comments and manual.
git clean -f -d # remove untracked
git clean -f -x -d # CAUTION: as above but removes ignored files like config.
git clean -fxd :/ # CAU... |
1230084 | How to have 'git log' show filenames like 'svn log -v' | 1,304 | 2009-08-04 21:46:36 | <p>SVN's log has a "-v" mode that outputs filenames of files changed in each commit, like so:</p>
<pre>jes5199$ svn log -v
------------------------------------------------------------------------
r1 | jes5199 | 2007-01-03 14:39:41 -0800 (Wed, 03 Jan 2007) | 1 line
Changed paths:
A /AUTHORS
A /COPYING
... | 635,024 | 13,195 | 2024-11-14 23:53:30 | 1,230,094 | 2,005 | 2009-08-04 21:48:33 | 19,563 | 2021-06-14 13:09:43 | https://stackoverflow.com/q/1230084 | https://stackoverflow.com/a/1230094 | <p>For full path names of changed files:</p>
<pre><code>git log --name-only
</code></pre>
<p>For full path names and status of changed files:</p>
<pre><code>git log --name-status
</code></pre>
<p>For abbreviated pathnames and a diffstat of changed files:</p>
<pre><code>git log --stat
</code></pre>
<p>There are a lot mo... | <p>For full path names of changed files:</p> <pre><code>git log --name-only </code></pre> <p>For full path names and status of changed files:</p> <pre><code>git log --name-status </code></pre> <p>For abbreviated pathnames and a diffstat of changed files:</p> <pre><code>git log --stat </code></pre> <p>There are a lot mo... | 63, 119, 942 | git, logging, svn | <h1>How to have 'git log' show filenames like 'svn log -v'</h1>
<p>SVN's log has a "-v" mode that outputs filenames of files changed in each commit, like so:</p>
<pre>jes5199$ svn log -v
------------------------------------------------------------------------
r1 | jes5199 | 2007-01-03 14:39:41 -0800 (Wed, 0... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,850 | git | # How to have 'git log' show filenames like 'svn log -v'
SVN's log has a "-v" mode that outputs filenames of files changed in each commit, like so:
```
jes5199$ svn log -v
------------------------------------------------------------------------
r1 | jes5199 | 2007-01-03 14:39:41 -0800 (Wed, 03 Jan 2007) | 1 line
Ch... | For full path names of changed files:
```
git log --name-only
```
For full path names and status of changed files:
```
git log --name-status
```
For abbreviated pathnames and a diffstat of changed files:
```
git log --stat
```
There are a lot more options. [Check out the documentation](https://git-scm.com/docs/gi... |
2563632 | How can I merge two commits into one if I already started rebase? | 1,404 | 2010-04-01 20:56:53 | <p>I am trying to merge 2 commits into 1, so I followed <a href="http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html" rel="noreferrer">“squashing commits with rebase” from git ready</a>.</p>
<p>I ran</p>
<pre><code>git rebase --interactive HEAD~2
</code></pre>
<p>In the resulti... | 1,253,869 | 286,802 | 2023-07-07 09:42:07 | 2,568,581 | 2,003 | 2010-04-02 19:04:45 | 123,109 | 2018-08-01 23:03:34 | https://stackoverflow.com/q/2563632 | https://stackoverflow.com/a/2568581 | <h3>Summary</h3>
<p>The error message</p>
<blockquote>
<p>Cannot 'squash' without a previous commit</p>
</blockquote>
<p>means you likely attempted to “squash downward.” <strong>Git always squashes a newer commit into an older commit</strong> or “upward” as viewed on the interactive rebase todo list, that is into ... | <h3>Summary</h3> <p>The error message</p> <blockquote> <p>Cannot 'squash' without a previous commit</p> </blockquote> <p>means you likely attempted to “squash downward.” <strong>Git always squashes a newer commit into an older commit</strong> or “upward” as viewed on the interactive rebase todo list, that is into ... | 119, 28897 | git, git-merge | <h1>How can I merge two commits into one if I already started rebase?</h1>
<p>I am trying to merge 2 commits into 1, so I followed <a href="http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html" rel="noreferrer">“squashing commits with rebase” from git ready</a>.</p>
<p>I ran</p>
... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,851 | git | # How can I merge two commits into one if I already started rebase?
I am trying to merge 2 commits into 1, so I followed [“squashing commits with rebase” from git ready](http://www.gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html).
I ran
```
git rebase --interactive HEAD~2
```
In the resulting ed... | ### Summary
The error message
> Cannot 'squash' without a previous commit
means you likely attempted to “squash downward.” **Git always squashes a newer commit into an older commit** or “upward” as viewed on the interactive rebase todo list, that is into a commit on a previous line. Changing the command on your todo... |
10054318 | How do I provide a username and password when running "git clone git@remote.git"? | 1,388 | 2012-04-07 12:05:22 | <p>I know how to include a username and password in an HTTPS <a href="https://git-scm.com/docs/git-clone#_git_urls" rel="noreferrer">Git URL</a> like this:</p>
<pre><code>git clone https://username:password@host
</code></pre>
<p>But I'd like to know how to provide a username and password to an SSH remote like this:</p>... | 2,929,249 | 807,914 | 2024-05-09 11:23:17 | 10,054,470 | 2,002 | 2012-04-07 12:25:00 | 797,672 | 2023-12-28 21:38:03 | https://stackoverflow.com/q/10054318 | https://stackoverflow.com/a/10054470 | <p>Based on <a href="https://stackoverflow.com/questions/10054318/how-do-i-provide-a-username-and-password-when-running-git-clone-gitremote-git#comment45751054_10054470">Michael Scharf's comment</a>:</p>
<p>You can leave out the password, so that it won't be logged in your Bash history file:</p>
<pre class="lang-none p... | <p>Based on <a href="https://stackoverflow.com/questions/10054318/how-do-i-provide-a-username-and-password-when-running-git-clone-gitremote-git#comment45751054_10054470">Michael Scharf's comment</a>:</p> <p>You can leave out the password, so that it won't be logged in your Bash history file:</p> <pre class="lang-none p... | 119 | git | <h1>How do I provide a username and password when running "git clone git@remote.git"?</h1>
<p>I know how to include a username and password in an HTTPS <a href="https://git-scm.com/docs/git-clone#_git_urls" rel="noreferrer">Git URL</a> like this:</p>
<pre><code>git clone https://username:password@host
</code></pre>
<p>... | q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10 | 13,852 | git | # How do I provide a username and password when running "git clone git@remote.git"?
I know how to include a username and password in an HTTPS [Git URL](https://git-scm.com/docs/git-clone#_git_urls) like this:
```
git clone https://username:password@host
```
But I'd like to know how to provide a username and password... | Based on [Michael Scharf's comment](https://stackoverflow.com/questions/10054318/how-do-i-provide-a-username-and-password-when-running-git-clone-gitremote-git#comment45751054_10054470):
You can leave out the password, so that it won't be logged in your Bash history file:
```
git clone https://username@github.com/user... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.