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
11706215
How can I fix the Git error "object file ... is empty"?
690
2012-07-29 02:38:10
<p>When I try to commit changes, I get this error:</p> <pre><code>error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is empty fatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0) is corrupt </code></pre> <p>I tried <code>g...
412,461
396,681
2025-02-14 09:36:50
12,371,337
1,228
2012-09-11 13:53:19
419,842
2021-08-29 13:13:23
https://stackoverflow.com/q/11706215
https://stackoverflow.com/a/12371337
<p>I had a similar problem. My laptop ran out of battery during a Git operation. Boo.</p> <p>I didn't have any backups. (N.B. Ubuntu One is not a backup solution for Git; it will helpfully overwrite your sane repository with your corrupted one.)</p> <p>To the Git wizards, if this was a bad way to fix it, please leave a...
<p>I had a similar problem. My laptop ran out of battery during a Git operation. Boo.</p> <p>I didn't have any backups. (N.B. Ubuntu One is not a backup solution for Git; it will helpfully overwrite your sane repository with your corrupted one.)</p> <p>To the Git wizards, if this was a bad way to fix it, please leave a...
119
git
<h1>How can I fix the Git error "object file ... is empty"?</h1> <p>When I try to commit changes, I get this error:</p> <pre><code>error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is empty fatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f2...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,966
git
# How can I fix the Git error "object file ... is empty"? When I try to commit changes, I get this error: ``` error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is empty fatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab...
I had a similar problem. My laptop ran out of battery during a Git operation. Boo. I didn't have any backups. (N.B. Ubuntu One is not a backup solution for Git; it will helpfully overwrite your sane repository with your corrupted one.) To the Git wizards, if this was a bad way to fix it, please leave a comment. It di...
25356810
How to squash all commits on branch
1,009
2014-08-18 05:25:39
<p>I make new branch from <code>master</code> with: </p> <pre><code>git checkout -b testbranch </code></pre> <p>I make 20 commits into it.</p> <p>Now I want to squash those 20 commits. I do that with:</p> <pre><code>git rebase -i HEAD~20 </code></pre> <p>What about if I don't know how many commits? Is there any wa...
1,130,269
3,803,850
2025-04-10 17:17:04
25,357,146
1,223
2014-08-18 05:59:47
6,309
2024-11-26 15:03:20
https://stackoverflow.com/q/25356810
https://stackoverflow.com/a/25357146
<p>Another way to squash all your commits is to reset the index to <code>master</code>:</p> <hr /> <p>Note: Git's default branch name is still <code>master</code> with Git version 2.41 (Q3 2023), as seen in <a href="https://git-scm.com/docs/git-init" rel="noreferrer"><code>git init</code> man page</a>.<br /> <a href="h...
<p>Another way to squash all your commits is to reset the index to <code>master</code>:</p> <hr /> <p>Note: Git's default branch name is still <code>master</code> with Git version 2.41 (Q3 2023), as seen in <a href="https://git-scm.com/docs/git-init" rel="noreferrer"><code>git init</code> man page</a>.<br /> <a href="h...
119, 456
git, version-control
<h1>How to squash all commits on branch</h1> <p>I make new branch from <code>master</code> with: </p> <pre><code>git checkout -b testbranch </code></pre> <p>I make 20 commits into it.</p> <p>Now I want to squash those 20 commits. I do that with:</p> <pre><code>git rebase -i HEAD~20 </code></pre> <p>What about if I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,967
git
# How to squash all commits on branch I make new branch from `master` with: ``` git checkout -b testbranch ``` I make 20 commits into it. Now I want to squash those 20 commits. I do that with: ``` git rebase -i HEAD~20 ``` What about if I don't know how many commits? Is there any way to do something like: ``` gi...
Another way to squash all your commits is to reset the index to `master`: --- Note: Git's default branch name is still `master` with Git version 2.41 (Q3 2023), as seen in [`git init` man page](https://git-scm.com/docs/git-init). [Git version 2.28 (Q3 2020)](https://stackoverflow.com/a/62983443/6309) introduced con...
10099258
How can I recover a lost commit in Git?
578
2012-04-11 03:04:02
<p>First, got "your branch is ahead of origin/master by 3 commits" then my app has reverted to an earlier time with earlier changes. </p> <p>How can I get what I spent the last 11 hours doing back?</p>
340,632
1,309,066
2024-03-19 21:43:06
10,099,285
1,220
2012-04-11 03:08:59
148,870
2021-07-28 21:00:50
https://stackoverflow.com/q/10099258
https://stackoverflow.com/a/10099285
<p><a href="https://git-scm.com/docs/git-reflog" rel="noreferrer"><code>git reflog</code></a> is your friend. Find the commit that you want to be on in that list and you can reset to it (for example:<code>git reset --hard e870e41</code>).</p> <p>(If you didn't commit your changes... you might be in trouble - commit ear...
<p><a href="https://git-scm.com/docs/git-reflog" rel="noreferrer"><code>git reflog</code></a> is your friend. Find the commit that you want to be on in that list and you can reset to it (for example:<code>git reset --hard e870e41</code>).</p> <p>(If you didn't commit your changes... you might be in trouble - commit ear...
119
git
<h1>How can I recover a lost commit in Git?</h1> <p>First, got "your branch is ahead of origin/master by 3 commits" then my app has reverted to an earlier time with earlier changes. </p> <p>How can I get what I spent the last 11 hours doing back?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,968
git
# How can I recover a lost commit in Git? First, got "your branch is ahead of origin/master by 3 commits" then my app has reverted to an earlier time with earlier changes. How can I get what I spent the last 11 hours doing back?
[`git reflog`](https://git-scm.com/docs/git-reflog) is your friend. Find the commit that you want to be on in that list and you can reset to it (for example:`git reset --hard e870e41`). (If you didn't commit your changes... you might be in trouble - commit early, and commit often!)
1441010
The shortest possible output from Git log, containing author and date
823
2009-09-17 19:58:33
<p>How can I show a Git log output with (at least) the following information?</p> <ul> <li>author</li> <li>commit date</li> <li>change</li> </ul> <p>I want it compressed to one line per log entry. What's the shortest possible format for that?</p> <p>(I tried <code>--format=oneline</code>, but that does not show the dat...
371,260
109,305
2025-07-25 18:34:43
1,441,062
1,219
2009-09-17 20:07:10
109,305
2025-07-25 13:59:44
https://stackoverflow.com/q/1441010
https://stackoverflow.com/a/1441062
<pre class="lang-none prettyprint-override"><code>git log --pretty=format:&quot;%h%x09%an%x09%ad%x09%s&quot; </code></pre> <p>does the job. This outputs:</p> <pre class="lang-none prettyprint-override"><code> fbc3503 mads Thu Dec 4 07:43:27 2008 +0000 show mobile if phone is null... ec36490 jesper Wed Nov 26 0...
<pre class="lang-none prettyprint-override"><code>git log --pretty=format:&quot;%h%x09%an%x09%ad%x09%s&quot; </code></pre> <p>does the job. This outputs:</p> <pre class="lang-none prettyprint-override"><code> fbc3503 mads Thu Dec 4 07:43:27 2008 +0000 show mobile if phone is null... ec36490 jesper Wed Nov 26 0...
119, 555, 942
formatting, git, logging
<h1>The shortest possible output from Git log, containing author and date</h1> <p>How can I show a Git log output with (at least) the following information?</p> <ul> <li>author</li> <li>commit date</li> <li>change</li> </ul> <p>I want it compressed to one line per log entry. What's the shortest possible format for that...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,969
git
# The shortest possible output from Git log, containing author and date How can I show a Git log output with (at least) the following information? - author - commit date - change I want it compressed to one line per log entry. What's the shortest possible format for that? (I tried `--format=oneline`, but that does ...
``` git log --pretty=format:"%h%x09%an%x09%ad%x09%s" ``` does the job. This outputs: ``` fbc3503 mads Thu Dec 4 07:43:27 2008 +0000 show mobile if phone is null... ec36490 jesper Wed Nov 26 05:41:37 2008 +0000 Cleanup after [942]: Using timezon ae62afd tobias Tue Nov 25 21:42:55 2008 +0000 Fixed #67 by...
673407
How do I clear my local working directory in Git?
798
2009-03-23 13:43:19
<p>How can I clear my working directory in Git?</p>
850,920
8,683
2025-04-16 16:05:52
675,797
1,211
2009-03-24 00:57:22
745
2019-09-01 12:25:01
https://stackoverflow.com/q/673407
https://stackoverflow.com/a/675797
<p>To reset a specific file to the last-committed state (to discard uncommitted changes in a specific file):</p> <pre><code>git checkout thefiletoreset.txt </code></pre> <p>This is mentioned in the <code>git status</code> output:</p> <pre><code>(use "git checkout -- &lt;file&gt;..." to discard changes in working dir...
<p>To reset a specific file to the last-committed state (to discard uncommitted changes in a specific file):</p> <pre><code>git checkout thefiletoreset.txt </code></pre> <p>This is mentioned in the <code>git status</code> output:</p> <pre><code>(use "git checkout -- &lt;file&gt;..." to discard changes in working dir...
119
git
<h1>How do I clear my local working directory in Git?</h1> <p>How can I clear my working directory in Git?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,970
git
# How do I clear my local working directory in Git? How can I clear my working directory in Git?
To reset a specific file to the last-committed state (to discard uncommitted changes in a specific file): ``` git checkout thefiletoreset.txt ``` This is mentioned in the `git status` output: ``` (use "git checkout -- <file>..." to discard changes in working directory) ``` To reset the entire repository to the last...
6448242
Git Push Error: insufficient permission for adding an object to repository database
830
2011-06-23 00:58:55
<p>When I try to push to a shared git remote, I get the following error: <code>insufficient permission for adding an object to repository database</code></p> <p>Then I read about a fix here: <a href="http://parizek.com/?p=177" rel="noreferrer">Fix</a> This worked for the next push, since all of the files were of the c...
759,042
469,106
2025-04-04 08:17:42
6,448,326
1,210
2011-06-23 01:13:50
712,605
2022-05-11 13:39:31
https://stackoverflow.com/q/6448242
https://stackoverflow.com/a/6448326
<h2>Repair Permissions</h2> <p>After you have identified and fixed the underlying cause (see below), you'll want to repair the permissions:</p> <pre><code>cd /path/to/repo/.git sudo chgrp -R groupname . sudo chmod -R g+rwX . sudo find . -type d -exec chmod g+s '{}' + </code></pre> <p>Note if you want everyone to be abl...
<h2>Repair Permissions</h2> <p>After you have identified and fixed the underlying cause (see below), you'll want to repair the permissions:</p> <pre><code>cd /path/to/repo/.git sudo chgrp -R groupname . sudo chmod -R g+rwX . sudo find . -type d -exec chmod g+s '{}' + </code></pre> <p>Note if you want everyone to be abl...
119, 4236
git, push
<h1>Git Push Error: insufficient permission for adding an object to repository database</h1> <p>When I try to push to a shared git remote, I get the following error: <code>insufficient permission for adding an object to repository database</code></p> <p>Then I read about a fix here: <a href="http://parizek.com/?p=177" ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,971
git
# Git Push Error: insufficient permission for adding an object to repository database When I try to push to a shared git remote, I get the following error: `insufficient permission for adding an object to repository database` Then I read about a fix here: [Fix](http://parizek.com/?p=177) This worked for the next push...
## Repair Permissions After you have identified and fixed the underlying cause (see below), you'll want to repair the permissions: ``` cd /path/to/repo/.git sudo chgrp -R groupname . sudo chmod -R g+rwX . sudo find . -type d -exec chmod g+s '{}' + ``` Note if you want everyone to be able to modify the repository, yo...
30024353
How can I use Visual Studio Code as the default editor for Git?
720
2015-05-04 07:03:43
<p>When using Git at the command line, I am wondering if it is possible to use Visual Studio Code as the default editor, i.e., when creating commit comments and looking at a diff of a file from the command line.</p> <p>I understand that it won't be possible to use it for doing merges (at least at the minute), but does ...
500,362
671,491
2025-09-13 01:26:26
36,644,561
1,208
2016-04-15 10:23:41
465,056
2023-10-08 07:18:21
https://stackoverflow.com/q/30024353
https://stackoverflow.com/a/36644561
<p>In the most recent release (v1.0, released in <strong>March 2016</strong>), you are now able to <a href="https://code.visualstudio.com/docs/editor/versioncontrol#_vs-code-as-git-editor" rel="noreferrer">use VS Code as the default git commit/diff tool</a>. Quoted from the documentations:</p> <blockquote> <ol> <li>Mak...
<p>In the most recent release (v1.0, released in <strong>March 2016</strong>), you are now able to <a href="https://code.visualstudio.com/docs/editor/versioncontrol#_vs-code-as-git-editor" rel="noreferrer">use VS Code as the default git commit/diff tool</a>. Quoted from the documentations:</p> <blockquote> <ol> <li>Mak...
119, 111608
git, visual-studio-code
<h1>How can I use Visual Studio Code as the default editor for Git?</h1> <p>When using Git at the command line, I am wondering if it is possible to use Visual Studio Code as the default editor, i.e., when creating commit comments and looking at a diff of a file from the command line.</p> <p>I understand that it won't b...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,972
git
# How can I use Visual Studio Code as the default editor for Git? When using Git at the command line, I am wondering if it is possible to use Visual Studio Code as the default editor, i.e., when creating commit comments and looking at a diff of a file from the command line. I understand that it won't be possible to u...
In the most recent release (v1.0, released in **March 2016**), you are now able to [use VS Code as the default git commit/diff tool](https://code.visualstudio.com/docs/editor/versioncontrol#_vs-code-as-git-editor). Quoted from the documentations: > 1. Make sure you can run `code --help` from the command line and you g...
5667884
How to squash commits in git after they have been pushed?
888
2011-04-14 18:31:50
<p>This gives a good explanation of squashing multiple commits:</p> <p><a href="http://git-scm.com/book/en/v2/Git-Branching-Rebasing" rel="noreferrer">http://git-scm.com/book/en/v2/Git-Branching-Rebasing</a></p> <p>but it does not work for commits that have already been pushed. How do I squash the most recent few commi...
717,895
627,729
2025-11-03 22:32:35
5,668,050
1,204
2011-04-14 18:43:54
66,353
2025-11-03 22:32:35
https://stackoverflow.com/q/5667884
https://stackoverflow.com/a/5668050
<p>Squash commits on the remote with:</p> <pre><code>git rebase -i origin/master~4 master </code></pre> <p>where <code>~4</code> means the last 4 commits.</p> <p>and then force push with :</p> <pre><code>git push origin +master </code></pre> <hr /> <h3>Difference between <code>--force</code> and <code>+</code></h3> <p>...
<p>Squash commits on the remote with:</p> <pre><code>git rebase -i origin/master~4 master </code></pre> <p>where <code>~4</code> means the last 4 commits.</p> <p>and then force push with :</p> <pre><code>git push origin +master </code></pre> <hr /> <h3>Difference between <code>--force</code> and <code>+</code></h3> <p>...
119, 42532
git, squash
<h1>How to squash commits in git after they have been pushed?</h1> <p>This gives a good explanation of squashing multiple commits:</p> <p><a href="http://git-scm.com/book/en/v2/Git-Branching-Rebasing" rel="noreferrer">http://git-scm.com/book/en/v2/Git-Branching-Rebasing</a></p> <p>but it does not work for commits that ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,973
git
# How to squash commits in git after they have been pushed? This gives a good explanation of squashing multiple commits: <http://git-scm.com/book/en/v2/Git-Branching-Rebasing> but it does not work for commits that have already been pushed. How do I squash the most recent few commits both in my local and remote repos...
Squash commits on the remote with: ``` git rebase -i origin/master~4 master ``` where `~4` means the last 4 commits. and then force push with : ``` git push origin +master ``` --- ### Difference between `--force` and `+` From the documentation of [`git push`](https://git-scm.com/docs/git-push#Documentation/git-p...
3046436
How do you stop tracking a remote branch in Git?
858
2010-06-15 15:06:32
<p>How do you stop tracking a remote branch in <a href="http://en.wikipedia.org/wiki/Git_%28software%29" rel="noreferrer">Git</a>?</p> <p>I am asking to stop tracking because in my concrete case, I want to delete the local branch, but not the remote one. Deleting the local one and pushing the deletion to remote will d...
427,778
4,926
2024-09-13 03:47:33
3,046,478
1,203
2010-06-15 15:11:39
6,309
2024-07-31 18:50:03
https://stackoverflow.com/q/3046436
https://stackoverflow.com/a/3046478
<p>As mentioned in <a href="https://stackoverflow.com/users/1541707/yoshua-wuyts">Yoshua Wuyts</a>' <a href="https://stackoverflow.com/a/29080220/6309">answer</a>, using <a href="http://git-scm.com/docs/git-branch" rel="noreferrer"><code>git branch</code></a>:</p> <pre><code>git branch --unset-upstream </code></pre> <h...
<p>As mentioned in <a href="https://stackoverflow.com/users/1541707/yoshua-wuyts">Yoshua Wuyts</a>' <a href="https://stackoverflow.com/a/29080220/6309">answer</a>, using <a href="http://git-scm.com/docs/git-branch" rel="noreferrer"><code>git branch</code></a>:</p> <pre><code>git branch --unset-upstream </code></pre> <h...
119, 1879, 96541
branch, git, git-track
<h1>How do you stop tracking a remote branch in Git?</h1> <p>How do you stop tracking a remote branch in <a href="http://en.wikipedia.org/wiki/Git_%28software%29" rel="noreferrer">Git</a>?</p> <p>I am asking to stop tracking because in my concrete case, I want to delete the local branch, but not the remote one. Deleti...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,974
git
# How do you stop tracking a remote branch in Git? How do you stop tracking a remote branch in [Git](http://en.wikipedia.org/wiki/Git_%28software%29)? I am asking to stop tracking because in my concrete case, I want to delete the local branch, but not the remote one. Deleting the local one and pushing the deletion to...
As mentioned in [Yoshua Wuyts](https://stackoverflow.com/users/1541707/yoshua-wuyts)' [answer](https://stackoverflow.com/a/29080220/6309), using [`git branch`](http://git-scm.com/docs/git-branch): ``` git branch --unset-upstream ``` ### Other options: You don't have to delete your local branch. Simply delete the lo...
7217894
moving changed files to another branch for check-in
661
2011-08-27 22:51:17
<p>This often happens to me: I write some code, go to check in my changes, and then realize I'm not in the proper branch to check in those changes. However I can't switch to another branch without my changes reverting. Is there a way to move changes to another branch to be checked in there?</p>
342,016
68,101
2025-11-20 14:54:25
7,218,106
1,199
2011-08-27 23:46:14
424,780
2024-02-19 12:07:05
https://stackoverflow.com/q/7217894
https://stackoverflow.com/a/7218106
<h2>Updated Answer</h2> <p>No need to use <code>stash</code> command. uncommitted changes do not belong to any branch so just use <code>git checkout -b &lt;new-branch&gt;</code></p> <hr /> <h2>Orginal Answer</h2> <p><code>git stash</code> is your friend.</p> <p>If you have not made the commit yet, just run <code>git st...
<h2>Updated Answer</h2> <p>No need to use <code>stash</code> command. uncommitted changes do not belong to any branch so just use <code>git checkout -b &lt;new-branch&gt;</code></p> <hr /> <h2>Orginal Answer</h2> <p><code>git stash</code> is your friend.</p> <p>If you have not made the commit yet, just run <code>git st...
119
git
<h1>moving changed files to another branch for check-in</h1> <p>This often happens to me: I write some code, go to check in my changes, and then realize I'm not in the proper branch to check in those changes. However I can't switch to another branch without my changes reverting. Is there a way to move changes to anothe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,975
git
# moving changed files to another branch for check-in This often happens to me: I write some code, go to check in my changes, and then realize I'm not in the proper branch to check in those changes. However I can't switch to another branch without my changes reverting. Is there a way to move changes to another branch ...
## Updated Answer No need to use `stash` command. uncommitted changes do not belong to any branch so just use `git checkout -b <new-branch>` --- ## Orginal Answer `git stash` is your friend. If you have not made the commit yet, just run `git stash`. This will save away all of your changes. Switch to the branch yo...
10827160
Undo a git stash
649
2012-05-31 03:44:38
<p>I just did a stash in a project that I haven't commit. Is there a way to go back to the state before I stashed? How could I do this? I've closed the terminal and my laptop is shut down. I've done some researched and it seems there's no way to do this.</p>
845,865
721,937
2021-08-01 16:17:59
10,827,172
1,199
2012-05-31 03:46:47
1,420,728
2016-05-02 18:44:51
https://stackoverflow.com/q/10827160
https://stackoverflow.com/a/10827172
<p>You can just run:</p> <pre><code>git stash pop </code></pre> <p>and it will unstash your changes.</p> <p>If you want to preserve the state of files (staged vs. working), use </p> <pre><code>git stash apply --index </code></pre>
<p>You can just run:</p> <pre><code>git stash pop </code></pre> <p>and it will unstash your changes.</p> <p>If you want to preserve the state of files (staged vs. working), use </p> <pre><code>git stash apply --index </code></pre>
119
git
<h1>Undo a git stash</h1> <p>I just did a stash in a project that I haven't commit. Is there a way to go back to the state before I stashed? How could I do this? I've closed the terminal and my laptop is shut down. I've done some researched and it seems there's no way to do this.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,976
git
# Undo a git stash I just did a stash in a project that I haven't commit. Is there a way to go back to the state before I stashed? How could I do this? I've closed the terminal and my laptop is shut down. I've done some researched and it seems there's no way to do this.
You can just run: ``` git stash pop ``` and it will unstash your changes. If you want to preserve the state of files (staged vs. working), use ``` git stash apply --index ```
13897717
Push commits to another branch
678
2012-12-16 01:12:02
<p>Is it possible to commit and push changes from one branch to another?</p> <p>Assume I committed changes in <code>BRANCH1</code> and want to push them to <code>BRANCH2</code>.</p> <p>From <code>BRANCH1</code>, is it valid to do:</p> <pre><code>git push origin BRANCH2 </code></pre> <p>And then reset <code>BRANCH1</cod...
897,454
1,641,422
2025-02-14 04:12:09
13,897,766
1,198
2012-12-16 01:23:59
34,397
2015-05-14 15:11:44
https://stackoverflow.com/q/13897717
https://stackoverflow.com/a/13897766
<p>That will almost work.</p> <p>When pushing to a non-default branch, you need to specify the source ref and the target ref:</p> <pre><code>git push origin branch1:branch2 </code></pre> <p>Or</p> <pre><code>git push &lt;remote&gt; &lt;branch with new changes&gt;:&lt;branch you are pushing to&gt; </code></pre>
<p>That will almost work.</p> <p>When pushing to a non-default branch, you need to specify the source ref and the target ref:</p> <pre><code>git push origin branch1:branch2 </code></pre> <p>Or</p> <pre><code>git push &lt;remote&gt; &lt;branch with new changes&gt;:&lt;branch you are pushing to&gt; </code></pre>
119, 76220
git, git-branch
<h1>Push commits to another branch</h1> <p>Is it possible to commit and push changes from one branch to another?</p> <p>Assume I committed changes in <code>BRANCH1</code> and want to push them to <code>BRANCH2</code>.</p> <p>From <code>BRANCH1</code>, is it valid to do:</p> <pre><code>git push origin BRANCH2 </code></p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,977
git
# Push commits to another branch Is it possible to commit and push changes from one branch to another? Assume I committed changes in `BRANCH1` and want to push them to `BRANCH2`. From `BRANCH1`, is it valid to do: ``` git push origin BRANCH2 ``` And then reset `BRANCH1`?
That will almost work. When pushing to a non-default branch, you need to specify the source ref and the target ref: ``` git push origin branch1:branch2 ``` Or ``` git push <remote> <branch with new changes>:<branch you are pushing to> ```
5751582
Fetch from origin with deleted remote branches
654
2011-04-22 01:56:17
<p>When I do <code>git fetch origin</code> and origin has a deleted branch, it doesn't seem to update it in my repository. When I do <code>git branch -r</code> it still shows <code>origin/DELETED_BRANCH</code>.</p> <p>How can I fix this?</p>
229,694
627,473
2025-04-28 20:12:37
5,751,635
1,198
2011-04-22 02:08:01
2,192,361
2021-04-18 15:46:25
https://stackoverflow.com/q/5751582
https://stackoverflow.com/a/5751635
<p>You need to do the following</p> <pre><code>git fetch -p </code></pre> <p>The <code>-p</code> or <code>--prune</code> argument will update the local database of remote branches.</p>
<p>You need to do the following</p> <pre><code>git fetch -p </code></pre> <p>The <code>-p</code> or <code>--prune</code> argument will update the local database of remote branches.</p>
119, 33720
git, git-fetch
<h1>Fetch from origin with deleted remote branches</h1> <p>When I do <code>git fetch origin</code> and origin has a deleted branch, it doesn't seem to update it in my repository. When I do <code>git branch -r</code> it still shows <code>origin/DELETED_BRANCH</code>.</p> <p>How can I fix this?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,978
git
# Fetch from origin with deleted remote branches When I do `git fetch origin` and origin has a deleted branch, it doesn't seem to update it in my repository. When I do `git branch -r` it still shows `origin/DELETED_BRANCH`. How can I fix this?
You need to do the following ``` git fetch -p ``` The `-p` or `--prune` argument will update the local database of remote branches.
3573623
How to preview the changes that "git stash apply" will make?
925
2010-08-26 09:08:05
<p>I want to inspect a stash and find out what changes it would make if I applied it to working tree in its current state.</p> <p>I know I can do a git diff on the stash, but this shows me all the differences between the working tree and the stash, whereas I'm just interested to know what the stash apply is going to ch...
229,957
11,410
2025-05-08 13:44:54
3,579,474
1,196
2010-08-26 21:01:08
163,759
2016-03-02 18:10:02
https://stackoverflow.com/q/3573623
https://stackoverflow.com/a/3579474
<p><code>git stash show</code> will show you the files that changed in your most recent stash. You can add the <code>-p</code> option to show the diff.</p> <pre><code>git stash show -p </code></pre> <p>If the stash you are interested in is not the most recent one, then add the name of the stash to the end of the com...
<p><code>git stash show</code> will show you the files that changed in your most recent stash. You can add the <code>-p</code> option to show the diff.</p> <pre><code>git stash show -p </code></pre> <p>If the stash you are interested in is not the most recent one, then add the name of the stash to the end of the com...
119, 13091
git, git-stash
<h1>How to preview the changes that "git stash apply" will make?</h1> <p>I want to inspect a stash and find out what changes it would make if I applied it to working tree in its current state.</p> <p>I know I can do a git diff on the stash, but this shows me all the differences between the working tree and the stash, w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,979
git
# How to preview the changes that "git stash apply" will make? I want to inspect a stash and find out what changes it would make if I applied it to working tree in its current state. I know I can do a git diff on the stash, but this shows me all the differences between the working tree and the stash, whereas I'm just...
`git stash show` will show you the files that changed in your most recent stash. You can add the `-p` option to show the diff. ``` git stash show -p ``` If the stash you are interested in is not the most recent one, then add the name of the stash to the end of the command: ``` git stash show -p stash@{2} ```
1817766
How to revert to origin's master branch's version of file
595
2009-11-30 03:53:24
<p>I'm in my local computer's master branch of a cloned master-branch of a repo from a remote server.</p> <p>I updated a file, and I want to revert back to the original version from the remote master branch.</p> <p>How can I do this?</p>
631,188
68,183
2023-05-23 14:20:15
1,817,774
1,196
2009-11-30 03:56:29
64,004
2017-11-03 12:30:34
https://stackoverflow.com/q/1817766
https://stackoverflow.com/a/1817774
<p>Assuming you did not commit the file, or add it to the index, then:</p> <pre><code>git checkout -- filename </code></pre> <p>Assuming you added it to the index, but did not commit it, then:</p> <pre><code>git reset HEAD filename git checkout -- filename </code></pre> <p>Assuming you did commit it, then:</p> <pr...
<p>Assuming you did not commit the file, or add it to the index, then:</p> <pre><code>git checkout -- filename </code></pre> <p>Assuming you added it to the index, but did not commit it, then:</p> <pre><code>git reset HEAD filename git checkout -- filename </code></pre> <p>Assuming you did commit it, then:</p> <pr...
119
git
<h1>How to revert to origin's master branch's version of file</h1> <p>I'm in my local computer's master branch of a cloned master-branch of a repo from a remote server.</p> <p>I updated a file, and I want to revert back to the original version from the remote master branch.</p> <p>How can I do this?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,980
git
# How to revert to origin's master branch's version of file I'm in my local computer's master branch of a cloned master-branch of a repo from a remote server. I updated a file, and I want to revert back to the original version from the remote master branch. How can I do this?
Assuming you did not commit the file, or add it to the index, then: ``` git checkout -- filename ``` Assuming you added it to the index, but did not commit it, then: ``` git reset HEAD filename git checkout -- filename ``` Assuming you did commit it, then: ``` git checkout origin/master filename ``` Assuming you ...
501407
Is there a git-merge --dry-run option?
1,054
2009-02-01 19:18:26
<p>I'm merging in a remote branch that may have a lot of conflicts. How can I tell if it will have conflicts or not?</p> <p>I don't see anything like a <code>--dry-run</code> on <code>git-merge</code>. </p>
345,260
9,594
2023-08-08 08:35:25
501,461
1,191
2009-02-01 19:57:26
28,804
2017-12-01 10:17:22
https://stackoverflow.com/q/501407
https://stackoverflow.com/a/501461
<p>As noted previously, pass in the <code>--no-commit</code> flag, but to avoid a fast-forward commit, also pass in <code>--no-ff</code>, like so:</p> <pre><code>$ git merge --no-commit --no-ff $BRANCH </code></pre> <p>To examine the staged changes:</p> <pre><code>$ git diff --cached </code></pre> <p>And you can un...
<p>As noted previously, pass in the <code>--no-commit</code> flag, but to avoid a fast-forward commit, also pass in <code>--no-ff</code>, like so:</p> <pre><code>$ git merge --no-commit --no-ff $BRANCH </code></pre> <p>To examine the staged changes:</p> <pre><code>$ git diff --cached </code></pre> <p>And you can un...
119, 28897
git, git-merge
<h1>Is there a git-merge --dry-run option?</h1> <p>I'm merging in a remote branch that may have a lot of conflicts. How can I tell if it will have conflicts or not?</p> <p>I don't see anything like a <code>--dry-run</code> on <code>git-merge</code>. </p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,981
git
# Is there a git-merge --dry-run option? I'm merging in a remote branch that may have a lot of conflicts. How can I tell if it will have conflicts or not? I don't see anything like a `--dry-run` on `git-merge`.
As noted previously, pass in the `--no-commit` flag, but to avoid a fast-forward commit, also pass in `--no-ff`, like so: ``` $ git merge --no-commit --no-ff $BRANCH ``` To examine the staged changes: ``` $ git diff --cached ``` And you can undo the merge, even if it is a fast-forward merge: ``` $ git merge --abor...
2733873
How can I revert a single file to a previous version?
893
2010-04-28 23:44:58
<p>Is there a way to go through different commits on a file. Say I modified a file 5 times and I want to go back to change 2, after I already committed and pushed to a repository.</p> <p>In my understanding the only way is to keep many branches, have I got that right? If I'm right I'm gonna have hundreds of branches ...
953,921
328,390
2021-02-25 14:46:04
2,734,035
1,187
2010-04-29 00:26:36
119,963
2010-10-26 12:48:55
https://stackoverflow.com/q/2733873
https://stackoverflow.com/a/2734035
<p>Let's start with a qualitative description of what we want to do (much of this is said in Ben Straub's answer). We've made some number of commits, five of which changed a given file, and we want to revert the file to one of the previous versions. First of all, git doesn't keep version numbers for individual files. I...
<p>Let's start with a qualitative description of what we want to do (much of this is said in Ben Straub's answer). We've made some number of commits, five of which changed a given file, and we want to revert the file to one of the previous versions. First of all, git doesn't keep version numbers for individual files. I...
119, 12309
git, revert
<h1>How can I revert a single file to a previous version?</h1> <p>Is there a way to go through different commits on a file. Say I modified a file 5 times and I want to go back to change 2, after I already committed and pushed to a repository.</p> <p>In my understanding the only way is to keep many branches, have I go...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,982
git
# How can I revert a single file to a previous version? Is there a way to go through different commits on a file. Say I modified a file 5 times and I want to go back to change 2, after I already committed and pushed to a repository. In my understanding the only way is to keep many branches, have I got that right? If ...
Let's start with a qualitative description of what we want to do (much of this is said in Ben Straub's answer). We've made some number of commits, five of which changed a given file, and we want to revert the file to one of the previous versions. First of all, git doesn't keep version numbers for individual files. It j...
4157189
How can I use `git pull` while ignoring local changes?
770
2010-11-11 17:19:48
<p>Is there a way to do a <code>git pull</code> that ignores any local file changes without blowing the directory away and having to perform a <code>git clone</code>?</p>
1,073,558
97,101
2025-03-30 23:09:02
4,157,261
1,185
2010-11-11 17:25:24
119,963
2021-03-03 08:59:02
https://stackoverflow.com/q/4157189
https://stackoverflow.com/a/4157261
<p>If you mean you want the pull to overwrite local changes, doing the merge as if the working tree were clean, well, clean the working tree:</p> <pre><code>git reset --hard git pull </code></pre> <p>If there are untracked local files you could use <code>git clean</code> to remove them.</p> <ul> <li><code>git clean -f<...
<p>If you mean you want the pull to overwrite local changes, doing the merge as if the working tree were clean, well, clean the working tree:</p> <pre><code>git reset --hard git pull </code></pre> <p>If there are untracked local files you could use <code>git clean</code> to remove them.</p> <ul> <li><code>git clean -f<...
119, 28896
git, git-pull
<h1>How can I use `git pull` while ignoring local changes?</h1> <p>Is there a way to do a <code>git pull</code> that ignores any local file changes without blowing the directory away and having to perform a <code>git clone</code>?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,983
git
# How can I use `git pull` while ignoring local changes? Is there a way to do a `git pull` that ignores any local file changes without blowing the directory away and having to perform a `git clone`?
If you mean you want the pull to overwrite local changes, doing the merge as if the working tree were clean, well, clean the working tree: ``` git reset --hard git pull ``` If there are untracked local files you could use `git clean` to remove them. - `git clean -f` to remove untracked files - `-df` to remove untrac...
5694389
Get the short Git version hash
648
2011-04-17 15:29:41
<p>Is there a cleaner way to get the short version hash of <code>HEAD</code> from Git?</p> <p>I want to see the same output as I get from:</p> <pre><code>git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8 </code></pre> <hr /> <p>I originally used the above command to generate a version string, but this is eve...
491,637
252,239
2025-08-30 21:16:16
5,694,416
1,175
2011-04-17 15:34:07
223,092
2018-11-04 03:14:14
https://stackoverflow.com/q/5694389
https://stackoverflow.com/a/5694416
<p>Try this:</p> <pre><code>git rev-parse --short HEAD </code></pre> <p>The command <code>git rev-parse</code> can do a remarkable number of different things, so you'd need to go through <a href="https://git-scm.com/docs/git-rev-parse" rel="noreferrer">the documentation</a> very carefully to spot that though.</p>
<p>Try this:</p> <pre><code>git rev-parse --short HEAD </code></pre> <p>The command <code>git rev-parse</code> can do a remarkable number of different things, so you'd need to go through <a href="https://git-scm.com/docs/git-rev-parse" rel="noreferrer">the documentation</a> very carefully to spot that though.</p>
119
git
<h1>Get the short Git version hash</h1> <p>Is there a cleaner way to get the short version hash of <code>HEAD</code> from Git?</p> <p>I want to see the same output as I get from:</p> <pre><code>git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8 </code></pre> <hr /> <p>I originally used the above command to ge...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,985
git
# Get the short Git version hash Is there a cleaner way to get the short version hash of `HEAD` from Git? I want to see the same output as I get from: ``` git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8 ``` --- I originally used the above command to generate a version string, but this is even better: ...
Try this: ``` git rev-parse --short HEAD ``` The command `git rev-parse` can do a remarkable number of different things, so you'd need to go through [the documentation](https://git-scm.com/docs/git-rev-parse) very carefully to spot that though.
4475457
Add all files to a commit except a single file?
911
2010-12-17 22:53:55
<p>I have a bunch of files in a changeset, but I want to specifically ignore a single modified file. The changeset looks like this after <code>git status</code>:</p> <pre><code># modified: main/dontcheckmein.txt # deleted: main/plzcheckmein.c # deleted: main/plzcheckmein2.c ... </code></pre> <p>Is there a way I...
692,409
291,701
2025-07-14 23:11:42
4,475,506
1,167
2010-12-17 23:00:00
479,989
2022-05-06 17:02:04
https://stackoverflow.com/q/4475457
https://stackoverflow.com/a/4475506
<pre><code>git add -u git reset -- main/dontcheckmein.txt </code></pre> <p><strong>Note</strong>: Git has subsequently added special syntax for this, which is explained in other answers.</p>
<pre><code>git add -u git reset -- main/dontcheckmein.txt </code></pre> <p><strong>Note</strong>: Git has subsequently added special syntax for this, which is explained in other answers.</p>
119, 34792
git, git-add
<h1>Add all files to a commit except a single file?</h1> <p>I have a bunch of files in a changeset, but I want to specifically ignore a single modified file. The changeset looks like this after <code>git status</code>:</p> <pre><code># modified: main/dontcheckmein.txt # deleted: main/plzcheckmein.c # deleted: m...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,986
git
# Add all files to a commit except a single file? I have a bunch of files in a changeset, but I want to specifically ignore a single modified file. The changeset looks like this after `git status`: ``` # modified: main/dontcheckmein.txt # deleted: main/plzcheckmein.c # deleted: main/plzcheckmein2.c ... ``` I...
``` git add -u git reset -- main/dontcheckmein.txt ``` **Note**: Git has subsequently added special syntax for this, which is explained in other answers.
3471827
How do I list all remote branches in Git 1.7+?
909
2010-08-12 20:37:33
<p>I've tried <code>git branch -r</code>, but that only lists remote branches that I've tracked locally. How do I find the list of those that I haven't? (It doesn't matter to me whether the command lists <em>all</em> remote branches or only those that are untracked.)</p>
791,427
1,190
2023-05-08 15:13:30
3,472,296
1,162
2010-08-12 21:44:00
39,975
2018-06-22 11:40:20
https://stackoverflow.com/q/3471827
https://stackoverflow.com/a/3472296
<p><strong>For the vast majority<sup>[1]</sup> of visitors here, <a href="https://stackoverflow.com/questions/3471827/how-do-i-list-all-remote-branches-in-git-1-7#comment39347566_3472296">the correct and simplest answer to the question</a> "How do I list all remote branches in Git 1.7+?" is:</strong></p> <pre><code>gi...
<p><strong>For the vast majority<sup>[1]</sup> of visitors here, <a href="https://stackoverflow.com/questions/3471827/how-do-i-list-all-remote-branches-in-git-1-7#comment39347566_3472296">the correct and simplest answer to the question</a> "How do I list all remote branches in Git 1.7+?" is:</strong></p> <pre><code>gi...
119, 1879, 31678, 76220
branch, git, git-branch, remote-branch
<h1>How do I list all remote branches in Git 1.7+?</h1> <p>I've tried <code>git branch -r</code>, but that only lists remote branches that I've tracked locally. How do I find the list of those that I haven't? (It doesn't matter to me whether the command lists <em>all</em> remote branches or only those that are untracke...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,987
git
# How do I list all remote branches in Git 1.7+? I've tried `git branch -r`, but that only lists remote branches that I've tracked locally. How do I find the list of those that I haven't? (It doesn't matter to me whether the command lists *all* remote branches or only those that are untracked.)
**For the vast majority[1] of visitors here, [the correct and simplest answer to the question](https://stackoverflow.com/questions/3471827/how-do-i-list-all-remote-branches-in-git-1-7#comment39347566_3472296) "How do I list all remote branches in Git 1.7+?" is:** ``` git branch -r ``` For a small minority[1] `git bra...
2530060
In plain English, what does "git reset" do?
819
2010-03-27 16:44:39
<p>I have seen <a href="https://stackoverflow.com/questions/1634115/whats-the-difference-between-git-reset-hard-and-git-reset-merge">interesting posts</a> explaining subtleties about <code>git reset</code>.</p> <p>Unfortunately, the more I read about it, the more it appears that I don't understand it fully. I come fro...
327,030
9,951
2023-04-17 16:33:02
2,530,073
1,160
2010-03-27 16:48:14
119,963
2016-06-15 14:26:55
https://stackoverflow.com/q/2530060
https://stackoverflow.com/a/2530073
<p>In general, <code>git reset</code>'s function is to take the current branch and reset it to point somewhere else, and possibly bring the index and work tree along. More concretely, if your master branch (currently checked out) is like this:</p> <pre><code>- A - B - C (HEAD, master) </code></pre> <p>and you realize...
<p>In general, <code>git reset</code>'s function is to take the current branch and reset it to point somewhere else, and possibly bring the index and work tree along. More concretely, if your master branch (currently checked out) is like this:</p> <pre><code>- A - B - C (HEAD, master) </code></pre> <p>and you realize...
119, 12626
git, reset
<h1>In plain English, what does "git reset" do?</h1> <p>I have seen <a href="https://stackoverflow.com/questions/1634115/whats-the-difference-between-git-reset-hard-and-git-reset-merge">interesting posts</a> explaining subtleties about <code>git reset</code>.</p> <p>Unfortunately, the more I read about it, the more it...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,988
git
# In plain English, what does "git reset" do? I have seen [interesting posts](https://stackoverflow.com/questions/1634115/whats-the-difference-between-git-reset-hard-and-git-reset-merge) explaining subtleties about `git reset`. Unfortunately, the more I read about it, the more it appears that I don't understand it fu...
In general, `git reset`'s function is to take the current branch and reset it to point somewhere else, and possibly bring the index and work tree along. More concretely, if your master branch (currently checked out) is like this: ``` - A - B - C (HEAD, master) ``` and you realize you want master to point to B, not C,...
4630704
Receiving "fatal: Not a git repository" when attempting to remote add a Git repo
567
2011-01-07 22:04:35
<p>I am following <a href="http://hayley.ws/2010/12/04/getting-jekyll-running.html" rel="noreferrer">this tutorial</a>. Everything works fine until I run this on my local machine (after replacing the <code>$VARIABLE</code>s with their actual values):</p> <pre><code>git remote add nfsn ssh://$USERNAME@$SERVER/home/priva...
1,585,228
498,656
2024-11-15 14:56:53
4,630,763
1,157
2011-01-07 22:13:21
11,208
2014-06-01 02:12:52
https://stackoverflow.com/q/4630704
https://stackoverflow.com/a/4630763
<p>Did you init a local Git repository, into which this remote is supposed to be added?</p> <p>Does your local directory have a <code>.git</code> folder?</p> <p>Try <code>git init</code>.</p>
<p>Did you init a local Git repository, into which this remote is supposed to be added?</p> <p>Does your local directory have a <code>.git</code> folder?</p> <p>Try <code>git init</code>.</p>
119
git
<h1>Receiving "fatal: Not a git repository" when attempting to remote add a Git repo</h1> <p>I am following <a href="http://hayley.ws/2010/12/04/getting-jekyll-running.html" rel="noreferrer">this tutorial</a>. Everything works fine until I run this on my local machine (after replacing the <code>$VARIABLE</code>s with t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,989
git
# Receiving "fatal: Not a git repository" when attempting to remote add a Git repo I am following [this tutorial](http://hayley.ws/2010/12/04/getting-jekyll-running.html). Everything works fine until I run this on my local machine (after replacing the `$VARIABLE`s with their actual values): ``` git remote add nfsn ss...
Did you init a local Git repository, into which this remote is supposed to be added? Does your local directory have a `.git` folder? Try `git init`.
22207256
Undo git stash pop that results in merge conflict
1,023
2014-03-05 19:25:18
<p>I began making changes to my codebase, not realizing I was on an old topic branch. To transfer them, I wanted to stash them and then apply them to a new branch off of master. I used <code>git stash pop</code> to transfer work-in-progress changes to this new branch, forgetting that I hadn't pulled new changes into ma...
658,986
807,674
2024-08-05 11:34:28
22,207,257
1,152
2014-03-05 19:25:18
807,674
2019-07-05 14:48:14
https://stackoverflow.com/q/22207256
https://stackoverflow.com/a/22207257
<p>As it turns out, Git is smart enough not to drop a stash if it doesn't apply cleanly. I was able to get to the desired state with the following steps:</p> <ol> <li>To unstage the merge conflicts: <code>git reset HEAD .</code> (note the trailing dot)</li> <li>To save the conflicted merge (just in case): <code>git st...
<p>As it turns out, Git is smart enough not to drop a stash if it doesn't apply cleanly. I was able to get to the desired state with the following steps:</p> <ol> <li>To unstage the merge conflicts: <code>git reset HEAD .</code> (note the trailing dot)</li> <li>To save the conflicted merge (just in case): <code>git st...
119, 13091
git, git-stash
<h1>Undo git stash pop that results in merge conflict</h1> <p>I began making changes to my codebase, not realizing I was on an old topic branch. To transfer them, I wanted to stash them and then apply them to a new branch off of master. I used <code>git stash pop</code> to transfer work-in-progress changes to this new ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,991
git
# Undo git stash pop that results in merge conflict I began making changes to my codebase, not realizing I was on an old topic branch. To transfer them, I wanted to stash them and then apply them to a new branch off of master. I used `git stash pop` to transfer work-in-progress changes to this new branch, forgetting t...
As it turns out, Git is smart enough not to drop a stash if it doesn't apply cleanly. I was able to get to the desired state with the following steps: 1. To unstage the merge conflicts: `git reset HEAD .` (note the trailing dot) 2. To save the conflicted merge (just in case): `git stash` 3. To return to master: `git c...
5340724
Get changes from master into branch in Git
1,035
2011-03-17 14:51:32
<p>In my repository I have a branch called <code>aq</code> which I'm working on.</p> <p>I then committed new work and bugs in <code>master</code>. </p> <p>What is the best way to get those commits into the <code>aq</code> branch? Create another new branch out of <code>master</code> and merge it with <code>aq</code>?<...
1,419,716
34,548
2024-03-03 10:11:32
5,340,773
1,147
2011-03-17 14:54:41
13,831
2016-07-05 16:06:43
https://stackoverflow.com/q/5340724
https://stackoverflow.com/a/5340773
<p>Check out the <code>aq</code> branch, and rebase from <code>master</code>.</p> <pre><code>git checkout aq git rebase master </code></pre>
<p>Check out the <code>aq</code> branch, and rebase from <code>master</code>.</p> <pre><code>git checkout aq git rebase master </code></pre>
119, 456, 28897
git, git-merge, version-control
<h1>Get changes from master into branch in Git</h1> <p>In my repository I have a branch called <code>aq</code> which I'm working on.</p> <p>I then committed new work and bugs in <code>master</code>. </p> <p>What is the best way to get those commits into the <code>aq</code> branch? Create another new branch out of <co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,992
git
# Get changes from master into branch in Git In my repository I have a branch called `aq` which I'm working on. I then committed new work and bugs in `master`. What is the best way to get those commits into the `aq` branch? Create another new branch out of `master` and merge it with `aq`?
Check out the `aq` branch, and rebase from `master`. ``` git checkout aq git rebase master ```
4025916
Git undo local branch delete
640
2010-10-26 16:50:14
<p>I just deleted the wrong branch with some experimental changes I need with <code>git branch -D branchName</code>.</p> <p>How do I recover the branch?</p>
222,799
78,182
2022-12-06 08:28:12
4,025,983
1,133
2010-10-26 16:57:06
144,846
2015-03-13 08:40:35
https://stackoverflow.com/q/4025916
https://stackoverflow.com/a/4025983
<p>You can use <a href="http://git-scm.com/docs/git-reflog" rel="noreferrer">git reflog</a> to find the SHA1 of the last commit of the branch. From that point, you can recreate a branch using</p> <pre><code>git branch branchName &lt;sha1&gt; </code></pre> <p><strong>Edit:</strong> As @seagullJS says, the <code>branch...
<p>You can use <a href="http://git-scm.com/docs/git-reflog" rel="noreferrer">git reflog</a> to find the SHA1 of the last commit of the branch. From that point, you can recreate a branch using</p> <pre><code>git branch branchName &lt;sha1&gt; </code></pre> <p><strong>Edit:</strong> As @seagullJS says, the <code>branch...
119, 1879, 76220
branch, git, git-branch
<h1>Git undo local branch delete</h1> <p>I just deleted the wrong branch with some experimental changes I need with <code>git branch -D branchName</code>.</p> <p>How do I recover the branch?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,994
git
# Git undo local branch delete I just deleted the wrong branch with some experimental changes I need with `git branch -D branchName`. How do I recover the branch?
You can use [git reflog](http://git-scm.com/docs/git-reflog) to find the SHA1 of the last commit of the branch. From that point, you can recreate a branch using ``` git branch branchName <sha1> ``` **Edit:** As @seagullJS says, the `branch -D` command tells you the sha1, so if you haven't closed the terminal yet it b...
1994463
How to cherry-pick a range of commits and merge them into another branch?
933
2010-01-03 09:50:23
<p>I have the following repository layout:</p> <ul> <li>master branch (production)</li> <li>integration</li> <li>working</li> </ul> <p>What I want to achieve is to cherry-pick a range of commits from the working branch and merge it into the integration branch. I'm pretty new to git and I can't figure out how to exactly...
651,954
131,404
2025-09-22 13:09:42
1,994,491
1,117
2010-01-03 10:08:04
6,309
2023-12-01 11:43:24
https://stackoverflow.com/q/1994463
https://stackoverflow.com/a/1994491
<p>When it comes to a range of commits, cherry-picking <del>is</del> <em>was</em> impractical.</p> <p>As <a href="https://stackoverflow.com/a/3664543/6309">mentioned below</a> by <a href="https://stackoverflow.com/users/442025/keith-kim">Keith Kim</a>, Git 1.7.2+ introduced the ability to cherry-pick a range of commits...
<p>When it comes to a range of commits, cherry-picking <del>is</del> <em>was</em> impractical.</p> <p>As <a href="https://stackoverflow.com/a/3664543/6309">mentioned below</a> by <a href="https://stackoverflow.com/users/442025/keith-kim">Keith Kim</a>, Git 1.7.2+ introduced the ability to cherry-pick a range of commits...
119, 28897, 78810
git, git-cherry-pick, git-merge
<h1>How to cherry-pick a range of commits and merge them into another branch?</h1> <p>I have the following repository layout:</p> <ul> <li>master branch (production)</li> <li>integration</li> <li>working</li> </ul> <p>What I want to achieve is to cherry-pick a range of commits from the working branch and merge it into ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,995
git
# How to cherry-pick a range of commits and merge them into another branch? I have the following repository layout: - master branch (production) - integration - working What I want to achieve is to cherry-pick a range of commits from the working branch and merge it into the integration branch. I'm pretty new to git ...
When it comes to a range of commits, cherry-picking ~~is~~ *was* impractical. As [mentioned below](https://stackoverflow.com/a/3664543/6309) by [Keith Kim](https://stackoverflow.com/users/442025/keith-kim), Git 1.7.2+ introduced the ability to cherry-pick a range of commits (but you still need to be aware of the [cons...
2183900
How do I prevent 'git diff' from using a pager?
961
2010-02-02 12:22:08
<p>Is there a command line switch to pass to <code>git diff</code> and other commands that use the <code>less</code> pager by default? I know these methods exist:</p> <ul> <li><code>git diff | cat</code>... removes all syntax highlighting</li> <li><code>git config --global core.pager cat</code> sets the pager in the gl...
257,204
55,562
2025-06-25 17:53:07
2,183,920
1,115
2010-02-02 12:25:33
20,862
2024-09-23 12:26:52
https://stackoverflow.com/q/2183900
https://stackoverflow.com/a/2183920
<p><code>--no-pager</code> to Git will tell it to not use a pager. Passing the option <code>-F</code> to <code>less</code> will tell it to not page if the output fits in a single screen.</p> <p>Make sure that you add <code>--no-pager</code> or <code>-P</code> <strong>before</strong> your command, as in <code>git --no-p...
<p><code>--no-pager</code> to Git will tell it to not use a pager. Passing the option <code>-F</code> to <code>less</code> will tell it to not page if the output fits in a single screen.</p> <p>Make sure that you add <code>--no-pager</code> or <code>-P</code> <strong>before</strong> your command, as in <code>git --no-p...
119
git
<h1>How do I prevent 'git diff' from using a pager?</h1> <p>Is there a command line switch to pass to <code>git diff</code> and other commands that use the <code>less</code> pager by default? I know these methods exist:</p> <ul> <li><code>git diff | cat</code>... removes all syntax highlighting</li> <li><code>git confi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,996
git
# How do I prevent 'git diff' from using a pager? Is there a command line switch to pass to `git diff` and other commands that use the `less` pager by default? I know these methods exist: - `git diff | cat`... removes all syntax highlighting - `git config --global core.pager cat` sets the pager in the global .gitconf...
`--no-pager` to Git will tell it to not use a pager. Passing the option `-F` to `less` will tell it to not page if the output fits in a single screen. Make sure that you add `--no-pager` or `-P` **before** your command, as in `git --no-pager log...`. Usage: ``` git --no-pager diff ``` Other options from the comment...
17404316
The following untracked working tree files would be overwritten by merge, but I don't care
814
2013-07-01 12:16:32
<p>On my branch I had some files in .gitignore</p> <p>On a different branch those files are not.</p> <p>I want to merge the different branch into mine, and I don't care if those files are no longer ignored or not.</p> <p>Unfortunately I get this: </p> <blockquote> <p>The following untracked working tree files wou...
1,421,563
727,429
2025-06-25 19:56:21
26,639,255
1,100
2014-10-29 19:44:42
2,399,517
2023-10-12 08:15:40
https://stackoverflow.com/q/17404316
https://stackoverflow.com/a/26639255
<p>The problem is that you are not tracking the files locally but identical files are tracked remotely so in order to &quot;pull&quot; your system would be forced to overwrite the local files which are not version controlled.</p> <p>Try running</p> <pre><code>git add * git stash git pull </code></pre> <p>This will trac...
<p>The problem is that you are not tracking the files locally but identical files are tracked remotely so in order to &quot;pull&quot; your system would be forced to overwrite the local files which are not version controlled.</p> <p>Try running</p> <pre><code>git add * git stash git pull </code></pre> <p>This will trac...
119, 717, 28897, 33720
git, git-fetch, git-merge, merge
<h1>The following untracked working tree files would be overwritten by merge, but I don't care</h1> <p>On my branch I had some files in .gitignore</p> <p>On a different branch those files are not.</p> <p>I want to merge the different branch into mine, and I don't care if those files are no longer ignored or not.</p> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,998
git
# The following untracked working tree files would be overwritten by merge, but I don't care On my branch I had some files in .gitignore On a different branch those files are not. I want to merge the different branch into mine, and I don't care if those files are no longer ignored or not. Unfortunately I get this: ...
The problem is that you are not tracking the files locally but identical files are tracked remotely so in order to "pull" your system would be forced to overwrite the local files which are not version controlled. Try running ``` git add * git stash git pull ``` This will track all files, remove all of your local cha...
4250063
How to .gitignore all files/folder in a folder, but not the folder itself?
1,228
2010-11-22 20:42:08
<p>I want to check in a blank folder to my Git repository. Effectively, I need to ignore all of the files and folders within the folder, but not the folder itself. How can I do this? What should I put in my <code>.gitignore</code> file?</p> <p>For those wondering why I would want to do this, I have an &quot;upload&quot...
777,237
294,619
2023-01-25 19:21:51
4,250,082
1,099
2010-11-22 20:43:48
28,422
2020-09-08 09:41:45
https://stackoverflow.com/q/4250063
https://stackoverflow.com/a/4250082
<p>You can't commit empty folders in git. If you want it to show up, you need to put something in it, even just an empty file.</p> <p>For example, add an empty file called <code>.gitkeep</code> to the folder you want to keep, then in your <code>.gitignore</code> file write:</p> <pre><code># exclude everything somefolde...
<p>You can't commit empty folders in git. If you want it to show up, you need to put something in it, even just an empty file.</p> <p>For example, add an empty file called <code>.gitkeep</code> to the folder you want to keep, then in your <code>.gitignore</code> file write:</p> <pre><code># exclude everything somefolde...
119, 25056
git, gitignore
<h1>How to .gitignore all files/folder in a folder, but not the folder itself?</h1> <p>I want to check in a blank folder to my Git repository. Effectively, I need to ignore all of the files and folders within the folder, but not the folder itself. How can I do this? What should I put in my <code>.gitignore</code> file?...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,999
git
# How to .gitignore all files/folder in a folder, but not the folder itself? I want to check in a blank folder to my Git repository. Effectively, I need to ignore all of the files and folders within the folder, but not the folder itself. How can I do this? What should I put in my `.gitignore` file? For those wonderin...
You can't commit empty folders in git. If you want it to show up, you need to put something in it, even just an empty file. For example, add an empty file called `.gitkeep` to the folder you want to keep, then in your `.gitignore` file write: ``` # exclude everything somefolder/* # exception to the rule !somefolder/...
7293008
Display last git commit comment
611
2011-09-03 12:06:51
<p>Often during a commit (<code>$ git -commit -m ""</code>), I wish to read my last comment to remember what progress I have made. Is there an easy way to directly access the last commit message through command-line? (I'm using Windows.)</p>
358,131
564,800
2023-03-02 20:20:14
7,293,026
1,096
2011-09-03 12:09:58
19,563
2011-09-03 12:09:58
https://stackoverflow.com/q/7293008
https://stackoverflow.com/a/7293026
<pre><code>git show </code></pre> <p>is the fastest to type, but shows you the diff as well.</p> <pre><code>git log -1 </code></pre> <p>is fast and simple.</p> <pre><code>git log -1 --pretty=%B </code></pre> <p>if you need just the commit message and nothing else.</p>
<pre><code>git show </code></pre> <p>is the fastest to type, but shows you the diff as well.</p> <pre><code>git log -1 </code></pre> <p>is fast and simple.</p> <pre><code>git log -1 --pretty=%B </code></pre> <p>if you need just the commit message and nothing else.</p>
119
git
<h1>Display last git commit comment</h1> <p>Often during a commit (<code>$ git -commit -m ""</code>), I wish to read my last comment to remember what progress I have made. Is there an easy way to directly access the last commit message through command-line? (I'm using Windows.)</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,000
git
# Display last git commit comment Often during a commit (`$ git -commit -m ""`), I wish to read my last comment to remember what progress I have made. Is there an easy way to directly access the last commit message through command-line? (I'm using Windows.)
``` git show ``` is the fastest to type, but shows you the diff as well. ``` git log -1 ``` is fast and simple. ``` git log -1 --pretty=%B ``` if you need just the commit message and nothing else.
1709177
Pull a certain branch from the remote server
953
2009-11-10 16:18:21
<p>Say that someone created a branch <code>xyz</code>. How do I pull the branch <code>xyz</code> from the remote server (e.g. <a href="http://en.wikipedia.org/wiki/GitHub" rel="noreferrer">GitHub</a>) and merge it into an existing branch <code>xyz</code> in my local repo?</p> <p>The answer to <em><a href="https://stack...
2,587,846
202,875
2024-08-20 12:36:48
1,710,474
1,085
2009-11-10 19:17:47
28,804
2009-11-10 19:17:47
https://stackoverflow.com/q/1709177
https://stackoverflow.com/a/1710474
<blockquote> <p>But I get an error "! [rejected]" and something about "non fast forward"</p> </blockquote> <p>That's because Git can't merge the changes from the branches into your current master. Let's say you've checked out branch <code>master</code>, and you want to merge in the remote branch <code>other-branch</...
<blockquote> <p>But I get an error "! [rejected]" and something about "non fast forward"</p> </blockquote> <p>That's because Git can't merge the changes from the branches into your current master. Let's say you've checked out branch <code>master</code>, and you want to merge in the remote branch <code>other-branch</...
119, 717, 1879, 4860
branch, git, merge, pull
<h1>Pull a certain branch from the remote server</h1> <p>Say that someone created a branch <code>xyz</code>. How do I pull the branch <code>xyz</code> from the remote server (e.g. <a href="http://en.wikipedia.org/wiki/GitHub" rel="noreferrer">GitHub</a>) and merge it into an existing branch <code>xyz</code> in my local...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,003
git
# Pull a certain branch from the remote server Say that someone created a branch `xyz`. How do I pull the branch `xyz` from the remote server (e.g. [GitHub](http://en.wikipedia.org/wiki/GitHub)) and merge it into an existing branch `xyz` in my local repo? The answer to *[Push branches to Git](https://stackoverflow.co...
> But I get an error "! [rejected]" and something about "non fast forward" That's because Git can't merge the changes from the branches into your current master. Let's say you've checked out branch `master`, and you want to merge in the remote branch `other-branch`. When you do this: ``` $ git pull origin other-branc...
610208
How to retrieve a single file from a specific revision in Git?
1,119
2009-03-04 11:43:13
<p>I have a Git repository and I'd like to see how some files looked a few months ago. I found the revision at that date; it's <code>27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8</code>. I need to see what one file looks like, and also save it as a ("new") file.</p> <p>I managed to see the file using <code>gitk</code>, but...
577,879
14,690
2025-09-21 18:18:34
610,315
1,078
2009-03-04 12:22:46
6,309
2025-09-21 18:18:34
https://stackoverflow.com/q/610208
https://stackoverflow.com/a/610315
<h2>Using <code>git show</code></h2> <p>To complete your own answer, the syntax for <a href="https://git-scm.com/docs/git-show" rel="noreferrer"><code>git show</code></a> is indeed:</p> <pre><code>git show object git show $REV:$FILE git show somebranch:from/the/root/myfile.txt git show HEAD^^^:test/test.py </code></pre...
<h2>Using <code>git show</code></h2> <p>To complete your own answer, the syntax for <a href="https://git-scm.com/docs/git-show" rel="noreferrer"><code>git show</code></a> is indeed:</p> <pre><code>git show object git show $REV:$FILE git show somebranch:from/the/root/myfile.txt git show HEAD^^^:test/test.py </code></pre...
119, 165501
git, git-restore
<h1>How to retrieve a single file from a specific revision in Git?</h1> <p>I have a Git repository and I'd like to see how some files looked a few months ago. I found the revision at that date; it's <code>27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8</code>. I need to see what one file looks like, and also save it as a ("ne...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,005
git
# How to retrieve a single file from a specific revision in Git? I have a Git repository and I'd like to see how some files looked a few months ago. I found the revision at that date; it's `27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8`. I need to see what one file looks like, and also save it as a ("new") file. I managed...
## Using `git show` To complete your own answer, the syntax for [`git show`](https://git-scm.com/docs/git-show) is indeed: ``` git show object git show $REV:$FILE git show somebranch:from/the/root/myfile.txt git show HEAD^^^:test/test.py ``` The command takes the usual style of revision, meaning you can use any of t...
278081
Resolving a Git conflict with binary files
597
2008-11-10 15:03:44
<p>I've been using Git on Windows (msysgit) to track changes for some design work I've been doing.</p> <p>Today I've been working on a different PC (with remote repo <code>brian</code>) and I'm now trying to merge the edits done today back into my regular local version on my laptop.</p> <p>On my laptop, I've used <co...
293,029
33,721
2022-09-18 19:23:17
2,163,926
1,077
2010-01-29 17:48:13
28,804
2017-07-20 22:01:45
https://stackoverflow.com/q/278081
https://stackoverflow.com/a/2163926
<p><code>git checkout</code> accepts an <code>--ours</code> or <code>--theirs</code> option for cases like this. So if you have a merge conflict, and you know you just want the file from the branch you are merging in, you can do:</p> <pre><code>$ git checkout --theirs -- path/to/conflicted-file.txt </code></pre> <p>t...
<p><code>git checkout</code> accepts an <code>--ours</code> or <code>--theirs</code> option for cases like this. So if you have a merge conflict, and you know you just want the file from the branch you are merging in, you can do:</p> <pre><code>$ git checkout --theirs -- path/to/conflicted-file.txt </code></pre> <p>t...
119, 62599
git, merge-conflict-resolution
<h1>Resolving a Git conflict with binary files</h1> <p>I've been using Git on Windows (msysgit) to track changes for some design work I've been doing.</p> <p>Today I've been working on a different PC (with remote repo <code>brian</code>) and I'm now trying to merge the edits done today back into my regular local versi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,006
git
# Resolving a Git conflict with binary files I've been using Git on Windows (msysgit) to track changes for some design work I've been doing. Today I've been working on a different PC (with remote repo `brian`) and I'm now trying to merge the edits done today back into my regular local version on my laptop. On my lap...
`git checkout` accepts an `--ours` or `--theirs` option for cases like this. So if you have a merge conflict, and you know you just want the file from the branch you are merging in, you can do: ``` $ git checkout --theirs -- path/to/conflicted-file.txt ``` to use that version of the file. Likewise, if you know you wa...
5120038
Is it possible to cherry-pick a commit from another git repository?
1,124
2011-02-25 16:47:41
<p>I'm working with a git repository that needs a commit from another git repository that knows nothing of the first.</p> <p>Typically I would cherry-pick using the <code>HEAD@{x}</code> in the reflog, but because this <code>.git</code> knows nothing of this reflog entry (different physical directory), how can I cherr...
476,392
634,519
2023-01-03 12:12:26
5,120,074
1,074
2011-02-25 16:50:46
11,343
2021-12-15 09:49:47
https://stackoverflow.com/q/5120038
https://stackoverflow.com/a/5120074
<p>You'll need to add the other repository as a remote, then fetch its changes. From there you see the commit and you can cherry-pick it.</p> <p>Like that:</p> <pre><code>git remote add other https://example.link/repository.git git fetch other </code></pre> <p>Now you have all the information to simply do <a href="http...
<p>You'll need to add the other repository as a remote, then fetch its changes. From there you see the commit and you can cherry-pick it.</p> <p>Like that:</p> <pre><code>git remote add other https://example.link/repository.git git fetch other </code></pre> <p>Now you have all the information to simply do <a href="http...
119, 36489
cherry-pick, git
<h1>Is it possible to cherry-pick a commit from another git repository?</h1> <p>I'm working with a git repository that needs a commit from another git repository that knows nothing of the first.</p> <p>Typically I would cherry-pick using the <code>HEAD@{x}</code> in the reflog, but because this <code>.git</code> knows...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,008
git
# Is it possible to cherry-pick a commit from another git repository? I'm working with a git repository that needs a commit from another git repository that knows nothing of the first. Typically I would cherry-pick using the `HEAD@{x}` in the reflog, but because this `.git` knows nothing of this reflog entry (differe...
You'll need to add the other repository as a remote, then fetch its changes. From there you see the commit and you can cherry-pick it. Like that: ``` git remote add other https://example.link/repository.git git fetch other ``` Now you have all the information to simply do [`git cherry-pick`](https://git-scm.com/docs...
12320863
How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?
723
2012-09-07 15:13:23
<p>I have a <code>.diff</code> file created by a coworker, and would like to apply the changes listed in that diff file to my local branch of the exact same repository. I do not have access to that worker's PC or branch that was used to generate this diff file.</p> <p>Obviously I could go line by line and retype every...
550,240
461,983
2024-07-02 13:54:13
12,320,940
1,071
2012-09-07 15:17:46
1,620,671
2015-03-27 06:19:13
https://stackoverflow.com/q/12320863
https://stackoverflow.com/a/12320940
<p>Copy the diff file to the root of your repository, and then do:</p> <pre><code>git apply yourcoworkers.diff </code></pre> <p>More information about the <code>apply</code> command is available on <a href="http://www.kernel.org/pub/software/scm/git/docs/git-apply.html">its man page</a>.</p> <p>By the way: A better ...
<p>Copy the diff file to the root of your repository, and then do:</p> <pre><code>git apply yourcoworkers.diff </code></pre> <p>More information about the <code>apply</code> command is available on <a href="http://www.kernel.org/pub/software/scm/git/docs/git-apply.html">its man page</a>.</p> <p>By the way: A better ...
119, 606, 9033
diff, git, git-diff
<h1>How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?</h1> <p>I have a <code>.diff</code> file created by a coworker, and would like to apply the changes listed in that diff file to my local branch of the exact same repository. I do not have access to that worker's ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,009
git
# How do you take a git diff file, and apply it to a local branch that is a copy of the same repository? I have a `.diff` file created by a coworker, and would like to apply the changes listed in that diff file to my local branch of the exact same repository. I do not have access to that worker's PC or branch that was...
Copy the diff file to the root of your repository, and then do: ``` git apply yourcoworkers.diff ``` More information about the `apply` command is available on [its man page](http://www.kernel.org/pub/software/scm/git/docs/git-apply.html). By the way: A better way to exchange whole commits by file is the combination...
13630849
Git - Difference Between 'assume-unchanged' and 'skip-worktree'
741
2012-11-29 17:00:25
<p>I have local changes to a file that I don't want to commit. It is a configuration file for building the application on a server, but I want to build locally with different settings. The file always shows up when I do 'git status' as something to be staged. I would like to hide this particular change and not commit i...
167,333
1,668,964
2026-01-24 17:01:32
13,631,525
1,070
2012-11-29 17:39:42
383,402
2024-02-08 18:01:34
https://stackoverflow.com/q/13630849
https://stackoverflow.com/a/13631525
<p>You want to use <code>skip-worktree</code>:</p> <pre><code>git update-index --skip-worktree &lt;file_name&gt; </code></pre> <p><code>assume-unchanged</code> is designed for cases where it is expensive to check whether a group of files have been modified; when you set the bit, <code>git</code> (of course) assumes the...
<p>You want to use <code>skip-worktree</code>:</p> <pre><code>git update-index --skip-worktree &lt;file_name&gt; </code></pre> <p><code>assume-unchanged</code> is designed for cases where it is expensive to check whether a group of files have been modified; when you set the bit, <code>git</code> (of course) assumes the...
119, 68400
git, git-index
<h1>Git - Difference Between 'assume-unchanged' and 'skip-worktree'</h1> <p>I have local changes to a file that I don't want to commit. It is a configuration file for building the application on a server, but I want to build locally with different settings. The file always shows up when I do 'git status' as something t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,010
git
# Git - Difference Between 'assume-unchanged' and 'skip-worktree' I have local changes to a file that I don't want to commit. It is a configuration file for building the application on a server, but I want to build locally with different settings. The file always shows up when I do 'git status' as something to be stag...
You want to use `skip-worktree`: ``` git update-index --skip-worktree <file_name> ``` `assume-unchanged` is designed for cases where it is expensive to check whether a group of files have been modified; when you set the bit, `git` (of course) assumes the files corresponding to that portion of the index have not been ...
9646167
Clean up a fork and restart it from the upstream
535
2012-03-10 11:48:22
<p>I have forked a repository, then I made some changes and it looks like I've messed up everything. </p> <p>I wish to start it again from scratch, using the current upstream/master as the base for my work.<br> Should I rebase my repository or delete it at all?</p>
231,383
485,241
2022-05-06 20:48:53
9,646,323
1,065
2012-03-10 12:12:24
6,309
2019-02-15 08:20:32
https://stackoverflow.com/q/9646167
https://stackoverflow.com/a/9646323
<p>The simplest solution would be (using '<code>upstream</code>' as the remote name referencing the original repo forked):</p> <pre><code>git remote add upstream /url/to/original/repo git fetch upstream git checkout master git reset --hard upstream/master git push origin master --force </code></pre> <p>(Similar to...
<p>The simplest solution would be (using '<code>upstream</code>' as the remote name referencing the original repo forked):</p> <pre><code>git remote add upstream /url/to/original/repo git fetch upstream git checkout master git reset --hard upstream/master git push origin master --force </code></pre> <p>(Similar to...
119
git
<h1>Clean up a fork and restart it from the upstream</h1> <p>I have forked a repository, then I made some changes and it looks like I've messed up everything. </p> <p>I wish to start it again from scratch, using the current upstream/master as the base for my work.<br> Should I rebase my repository or delete it at all...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,011
git
# Clean up a fork and restart it from the upstream I have forked a repository, then I made some changes and it looks like I've messed up everything. I wish to start it again from scratch, using the current upstream/master as the base for my work. Should I rebase my repository or delete it at all?
The simplest solution would be (using '`upstream`' as the remote name referencing the original repo forked): ``` git remote add upstream /url/to/original/repo git fetch upstream git checkout master git reset --hard upstream/master git push origin master --force ``` (Similar to this [GitHub page, section "What shoul...
5816134
How to find the Git commit that introduced a string in any branch?
594
2011-04-28 08:58:59
<p>I want to be able to find a certain string which was introduced in any commit in any branch, how can I do that? I found something (that I modified for Win32), but <code>git whatchanged</code> doesn't seem to be looking into the different branches (ignore the py3k chunk, it's just a msys/win line feed fix)</p> <pre ...
189,340
87,973
2023-07-12 20:47:29
5,816,177
1,062
2011-04-28 09:03:46
223,092
2022-08-01 17:39:22
https://stackoverflow.com/q/5816134
https://stackoverflow.com/a/5816177
<p>You can do:</p> <pre><code>git log -S &lt;search string&gt; --source --all </code></pre> <p>To find all commits that added or removed the <strong>fixed string</strong> <code>search string</code>. The <code>--all</code> parameter means to start from every branch and <code>--source</code> means to show which of those...
<p>You can do:</p> <pre><code>git log -S &lt;search string&gt; --source --all </code></pre> <p>To find all commits that added or removed the <strong>fixed string</strong> <code>search string</code>. The <code>--all</code> parameter means to start from every branch and <code>--source</code> means to show which of those...
119, 816
git, search
<h1>How to find the Git commit that introduced a string in any branch?</h1> <p>I want to be able to find a certain string which was introduced in any commit in any branch, how can I do that? I found something (that I modified for Win32), but <code>git whatchanged</code> doesn't seem to be looking into the different bra...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,012
git
# How to find the Git commit that introduced a string in any branch? I want to be able to find a certain string which was introduced in any commit in any branch, how can I do that? I found something (that I modified for Win32), but `git whatchanged` doesn't seem to be looking into the different branches (ignore the py...
You can do: ``` git log -S <search string> --source --all ``` To find all commits that added or removed the **fixed string** `search string`. The `--all` parameter means to start from every branch and `--source` means to show which of those branches led to finding that commit. It's often useful to add `-p` to show th...
4308610
How to ignore certain files in Git
998
2010-11-29 22:12:24
<p>I have a repository with a file, <code>Hello.java</code>. When I compile it, an additional <code>Hello.class</code> file is generated.</p> <p>I created an entry for <code>Hello.class</code> in a <code>.gitignore</code> file. However, the file still appears to be tracked.</p> <p>How can I make Git ignore <code>Hell...
1,635,188
514,612
2025-02-25 21:22:51
4,308,645
1,057
2010-11-29 22:16:57
206,720
2019-08-04 20:38:34
https://stackoverflow.com/q/4308610
https://stackoverflow.com/a/4308645
<p>The problem is that <code>.gitignore</code> ignores just files that weren't tracked before (by <code>git add</code>). Run <code>git reset name_of_file</code> to unstage the file and keep it. In case you want to also remove the given file from the repository (after pushing), use <code>git rm --cached name_of_file</co...
<p>The problem is that <code>.gitignore</code> ignores just files that weren't tracked before (by <code>git add</code>). Run <code>git reset name_of_file</code> to unstage the file and keep it. In case you want to also remove the given file from the repository (after pushing), use <code>git rm --cached name_of_file</co...
119, 25056
git, gitignore
<h1>How to ignore certain files in Git</h1> <p>I have a repository with a file, <code>Hello.java</code>. When I compile it, an additional <code>Hello.class</code> file is generated.</p> <p>I created an entry for <code>Hello.class</code> in a <code>.gitignore</code> file. However, the file still appears to be tracked.<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,013
git
# How to ignore certain files in Git I have a repository with a file, `Hello.java`. When I compile it, an additional `Hello.class` file is generated. I created an entry for `Hello.class` in a `.gitignore` file. However, the file still appears to be tracked. How can I make Git ignore `Hello.class`?
The problem is that `.gitignore` ignores just files that weren't tracked before (by `git add`). Run `git reset name_of_file` to unstage the file and keep it. In case you want to also remove the given file from the repository (after pushing), use `git rm --cached name_of_file`.
20280726
How to clone a specific Git tag
630
2013-11-29 07:46:24
<p>From <a href="http://git-scm.com/docs/git-clone">git-clone(1) Manual Page</a></p> <blockquote> <p><code>--branch</code> can also take tags and detaches the HEAD at that commit in the resulting repository.</p> </blockquote> <p>I tried </p> <pre><code>git clone --branch &lt;tag_name&gt; &lt;repo_url&gt; </code><...
773,268
928,866
2023-02-13 06:37:22
21,699,307
1,056
2014-02-11 10:32:03
1,257,778
2020-07-17 10:11:09
https://stackoverflow.com/q/20280726
https://stackoverflow.com/a/21699307
<pre><code>git clone --depth 1 --branch &lt;tag_name&gt; &lt;repo_url&gt; </code></pre> <p><code>--depth 1</code> is optional but if you only need the state at that one revision, you probably want to skip downloading all the history up to that revision.</p>
<pre><code>git clone --depth 1 --branch &lt;tag_name&gt; &lt;repo_url&gt; </code></pre> <p><code>--depth 1</code> is optional but if you only need the state at that one revision, you probably want to skip downloading all the history up to that revision.</p>
119, 34099, 60718
git, git-clone, git-tag
<h1>How to clone a specific Git tag</h1> <p>From <a href="http://git-scm.com/docs/git-clone">git-clone(1) Manual Page</a></p> <blockquote> <p><code>--branch</code> can also take tags and detaches the HEAD at that commit in the resulting repository.</p> </blockquote> <p>I tried </p> <pre><code>git clone --branch &...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,014
git
# How to clone a specific Git tag From [git-clone(1) Manual Page](http://git-scm.com/docs/git-clone) > `--branch` can also take tags and detaches the HEAD at that commit in the resulting repository. I tried ``` git clone --branch <tag_name> <repo_url> ``` But it does not work. It returns: ``` warning: Remote bran...
``` git clone --depth 1 --branch <tag_name> <repo_url> ``` `--depth 1` is optional but if you only need the state at that one revision, you probably want to skip downloading all the history up to that revision.
3876977
Update Git branches from master
1,120
2010-10-06 21:18:19
<p>I have four branches (master, b1, b2, and b3). After I worked on b1-b3, I realized I have something to change on branch master that should be in all other branches. I changed what I needed in <code>master</code> and... here is my problem:</p> <p>How do I update all other branches with <code>master</code> branch code...
1,601,747
23,810
2023-05-10 21:31:00
3,877,000
1,053
2010-10-06 21:21:02
171,742
2016-02-04 16:13:16
https://stackoverflow.com/q/3876977
https://stackoverflow.com/a/3877000
<p>You have two options:</p> <p>The first is a merge, but this creates an extra commit for the merge. </p> <p>Checkout each branch:</p> <pre><code>git checkout b1 </code></pre> <p>Then merge:</p> <pre><code>git merge origin/master </code></pre> <p>Then push:</p> <pre><code>git push origin b1 </code></pre> <p>Al...
<p>You have two options:</p> <p>The first is a merge, but this creates an extra commit for the merge. </p> <p>Checkout each branch:</p> <pre><code>git checkout b1 </code></pre> <p>Then merge:</p> <pre><code>git merge origin/master </code></pre> <p>Then push:</p> <pre><code>git push origin b1 </code></pre> <p>Al...
119, 76220
git, git-branch
<h1>Update Git branches from master</h1> <p>I have four branches (master, b1, b2, and b3). After I worked on b1-b3, I realized I have something to change on branch master that should be in all other branches. I changed what I needed in <code>master</code> and... here is my problem:</p> <p>How do I update all other bran...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,015
git
# Update Git branches from master I have four branches (master, b1, b2, and b3). After I worked on b1-b3, I realized I have something to change on branch master that should be in all other branches. I changed what I needed in `master` and... here is my problem: How do I update all other branches with `master` branch ...
You have two options: The first is a merge, but this creates an extra commit for the merge. Checkout each branch: ``` git checkout b1 ``` Then merge: ``` git merge origin/master ``` Then push: ``` git push origin b1 ``` Alternatively, you can do a rebase: ``` git fetch git rebase origin/master ```
767147
How can I stop .gitignore from appearing in the list of untracked files?
1,046
2009-04-20 06:42:27
<p>I just did a <code>git init</code> on the root of my new project.</p> <p>Then I created a <code>.gitignore</code> file.</p> <p>Now, when I type <code>git status</code>, <strong>.gitignore</strong> file appears in the list of untracked files. Why is that?</p>
453,380
27,328
2025-09-28 07:22:08
767,213
1,053
2009-04-20 07:11:45
26,051
2015-01-02 10:24:30
https://stackoverflow.com/q/767147
https://stackoverflow.com/a/767213
<p>The <code>.gitignore</code> file should be in your repository, so it should indeed be added and committed in, as <code>git status</code> suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.</p> <p>So, add it to your repository, it should not be gitignored.</p> <p>If ...
<p>The <code>.gitignore</code> file should be in your repository, so it should indeed be added and committed in, as <code>git status</code> suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.</p> <p>So, add it to your repository, it should not be gitignored.</p> <p>If ...
119, 456, 3346, 25056
dvcs, git, gitignore, version-control
<h1>How can I stop .gitignore from appearing in the list of untracked files?</h1> <p>I just did a <code>git init</code> on the root of my new project.</p> <p>Then I created a <code>.gitignore</code> file.</p> <p>Now, when I type <code>git status</code>, <strong>.gitignore</strong> file appears in the list of untracke...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,016
git
# How can I stop .gitignore from appearing in the list of untracked files? I just did a `git init` on the root of my new project. Then I created a `.gitignore` file. Now, when I type `git status`, **.gitignore** file appears in the list of untracked files. Why is that?
The `.gitignore` file should be in your repository, so it should indeed be added and committed in, as `git status` suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on. So, add it to your repository, it should not be gitignored. If you really want you can add `.gitignore...
8939977
Git push rejected after feature branch rebase
1,391
2012-01-20 10:29:27
<p>OK, I thought this was a simple git scenario, what am I missing?</p> <p>I have a <code>master</code> branch and a <code>feature</code> branch. I do some work on <code>master</code>, some on <code>feature</code>, and then some more on <code>master</code>. I end up with something like this (lexicographic order implie...
531,340
24,545
2025-09-05 06:34:29
8,940,299
1,047
2012-01-20 10:55:34
357,743
2025-09-05 06:34:29
https://stackoverflow.com/q/8939977
https://stackoverflow.com/a/8940299
<p>The problem is that <code>git push</code> assumes that the remote branch can be fast-forwarded to your local branch. That is, that the only difference between the local and remote branches is that the local one has some new commits at the end, like:</p> <pre><code>Z--X--R &lt;- origin/some-branch (can be fas...
<p>The problem is that <code>git push</code> assumes that the remote branch can be fast-forwarded to your local branch. That is, that the only difference between the local and remote branches is that the local one has some new commits at the end, like:</p> <pre><code>Z--X--R &lt;- origin/some-branch (can be fas...
119
git
<h1>Git push rejected after feature branch rebase</h1> <p>OK, I thought this was a simple git scenario, what am I missing?</p> <p>I have a <code>master</code> branch and a <code>feature</code> branch. I do some work on <code>master</code>, some on <code>feature</code>, and then some more on <code>master</code>. I end ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,018
git
# Git push rejected after feature branch rebase OK, I thought this was a simple git scenario, what am I missing? I have a `master` branch and a `feature` branch. I do some work on `master`, some on `feature`, and then some more on `master`. I end up with something like this (lexicographic order implies the order of c...
The problem is that `git push` assumes that the remote branch can be fast-forwarded to your local branch. That is, that the only difference between the local and remote branches is that the local one has some new commits at the end, like: ``` Z--X--R <- origin/some-branch (can be fast-forwarded to Y commit) ...
1404796
How can I get the latest tag name in current branch in Git?
748
2009-09-10 11:43:39
<p>What's the simplest way to get the most recent tag in Git?</p> <pre><code>git tag a HEAD git tag b HEAD^^ git tag c HEAD^ git tag </code></pre> <p>output:</p> <pre><code>a b c </code></pre> <p>Should I write a script to get each tag's datetime and compare them?</p>
552,000
171,278
2024-12-27 15:35:47
7,261,049
1,045
2011-08-31 17:39:29
922,145
2020-10-18 20:30:38
https://stackoverflow.com/q/1404796
https://stackoverflow.com/a/7261049
<p>To get the most recent tag (example output afterwards):</p> <pre><code>git describe --tags --abbrev=0 # 0.1.0-dev </code></pre> <p>To get the most recent tag, with the number of additional commits on top of the tagged object &amp; more:</p> <pre><code>git describe --tags # 0.1.0-dev-93-g1416689 </code...
<p>To get the most recent tag (example output afterwards):</p> <pre><code>git describe --tags --abbrev=0 # 0.1.0-dev </code></pre> <p>To get the most recent tag, with the number of additional commits on top of the tagged object &amp; more:</p> <pre><code>git describe --tags # 0.1.0-dev-93-g1416689 </code...
119, 37230, 58871, 60718
getlatest, git, git-checkout, git-tag
<h1>How can I get the latest tag name in current branch in Git?</h1> <p>What's the simplest way to get the most recent tag in Git?</p> <pre><code>git tag a HEAD git tag b HEAD^^ git tag c HEAD^ git tag </code></pre> <p>output:</p> <pre><code>a b c </code></pre> <p>Should I write a script to get each tag's datetime ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,020
git
# How can I get the latest tag name in current branch in Git? What's the simplest way to get the most recent tag in Git? ``` git tag a HEAD git tag b HEAD^^ git tag c HEAD^ git tag ``` output: ``` a b c ``` Should I write a script to get each tag's datetime and compare them?
To get the most recent tag (example output afterwards): ``` git describe --tags --abbrev=0 # 0.1.0-dev ``` To get the most recent tag, with the number of additional commits on top of the tagged object & more: ``` git describe --tags # 0.1.0-dev-93-g1416689 ``` To get the most recent *annotated* tag: ...
9591407
Unstage a deleted file in git
667
2012-03-06 20:33:42
<p>Usually, to discard changes to a file you would do:</p> <pre><code>git checkout -- &lt;file&gt; </code></pre> <p>What if the change I want to discard is deleting the file? The above line would give an error:</p> <pre><code>error: pathspec '&lt;file&gt;' did not match any file(s) known to git. </code></pre> <p>Wh...
319,449
170,521
2023-10-10 19:28:57
9,591,612
1,035
2012-03-06 20:46:25
1,253,222
2018-12-05 23:09:55
https://stackoverflow.com/q/9591407
https://stackoverflow.com/a/9591612
<p>Assuming you're wanting to undo the effects of <code>git rm &lt;file&gt;</code> or <code>rm &lt;file&gt;</code> followed by <code>git add -A</code> or something similar:</p> <pre><code># this restores the file status in the index git reset -- &lt;file&gt; # then check out a copy from the index git checkout -- &lt;f...
<p>Assuming you're wanting to undo the effects of <code>git rm &lt;file&gt;</code> or <code>rm &lt;file&gt;</code> followed by <code>git add -A</code> or something similar:</p> <pre><code># this restores the file status in the index git reset -- &lt;file&gt; # then check out a copy from the index git checkout -- &lt;f...
119, 37230
git, git-checkout
<h1>Unstage a deleted file in git</h1> <p>Usually, to discard changes to a file you would do:</p> <pre><code>git checkout -- &lt;file&gt; </code></pre> <p>What if the change I want to discard is deleting the file? The above line would give an error:</p> <pre><code>error: pathspec '&lt;file&gt;' did not match any fil...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,023
git
# Unstage a deleted file in git Usually, to discard changes to a file you would do: ``` git checkout -- <file> ``` What if the change I want to discard is deleting the file? The above line would give an error: ``` error: pathspec '<file>' did not match any file(s) known to git. ``` What command will restore that s...
Assuming you're wanting to undo the effects of `git rm <file>` or `rm <file>` followed by `git add -A` or something similar: ``` # this restores the file status in the index git reset -- <file> # then check out a copy from the index git checkout -- <file> ``` To undo `git add <file>`, the first line above suffices, a...
5094293
Git remote branch deleted, but still it appears in 'branch -a'
844
2011-02-23 17:10:57
<p>Let's say I had a branch named <code>coolbranch</code> in my repository.</p> <p>Now, I decided to delete it (both remotely and locally) with:</p> <pre><code>git push origin :coolbranch git branch -D coolbranch </code></pre> <p>Great! Now the branch is really deleted.</p> <p>But when I run</p> <pre><code>git bra...
287,947
414,037
2025-09-25 07:52:12
5,096,739
1,027
2011-02-23 20:32:35
223,092
2022-10-05 04:30:56
https://stackoverflow.com/q/5094293
https://stackoverflow.com/a/5096739
<p><code>git remote prune origin</code> will remove all such stale branches. That's probably what you'd want in most cases, but if you want to just remove that particular remote-tracking branch, you should do:</p> <pre><code>git branch -d -r origin/coolbranch </code></pre> <p>(The <code>-r</code> is easy to forget...)<...
<p><code>git remote prune origin</code> will remove all such stale branches. That's probably what you'd want in most cases, but if you want to just remove that particular remote-tracking branch, you should do:</p> <pre><code>git branch -d -r origin/coolbranch </code></pre> <p>(The <code>-r</code> is easy to forget...)<...
119, 76220
git, git-branch
<h1>Git remote branch deleted, but still it appears in 'branch -a'</h1> <p>Let's say I had a branch named <code>coolbranch</code> in my repository.</p> <p>Now, I decided to delete it (both remotely and locally) with:</p> <pre><code>git push origin :coolbranch git branch -D coolbranch </code></pre> <p>Great! Now the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,026
git
# Git remote branch deleted, but still it appears in 'branch -a' Let's say I had a branch named `coolbranch` in my repository. Now, I decided to delete it (both remotely and locally) with: ``` git push origin :coolbranch git branch -D coolbranch ``` Great! Now the branch is really deleted. But when I run ``` git ...
`git remote prune origin` will remove all such stale branches. That's probably what you'd want in most cases, but if you want to just remove that particular remote-tracking branch, you should do: ``` git branch -d -r origin/coolbranch ``` (The `-r` is easy to forget...) `-r` in this case will "List or delete (if use...
1526044
Partly cherry-picking a commit with Git
624
2009-10-06 14:47:04
<p>I'm working on 2 different branches: <strong>release</strong> and <strong>development</strong>. </p> <p>I noticed I still need to integrate some changes that were committed to the <strong>release</strong> branch back into the <strong>development</strong> branch. </p> <p>The problem is I don't need all of the comm...
180,586
139,990
2024-05-01 17:39:48
1,526,093
1,023
2009-10-06 14:51:44
119,963
2021-12-09 05:35:03
https://stackoverflow.com/q/1526044
https://stackoverflow.com/a/1526093
<p>The core thing you're going to want here is <code>git add -p</code> (<code>-p</code> is a synonym for <code>--patch</code>). This provides an interactive way to add in content, letting you decide whether each hunk should go in or not, and even letting you manually edit the patch if necessary.</p> <p>To use it in com...
<p>The core thing you're going to want here is <code>git add -p</code> (<code>-p</code> is a synonym for <code>--patch</code>). This provides an interactive way to add in content, letting you decide whether each hunk should go in or not, and even letting you manually edit the patch if necessary.</p> <p>To use it in com...
119, 78810
git, git-cherry-pick
<h1>Partly cherry-picking a commit with Git</h1> <p>I'm working on 2 different branches: <strong>release</strong> and <strong>development</strong>. </p> <p>I noticed I still need to integrate some changes that were committed to the <strong>release</strong> branch back into the <strong>development</strong> branch. </p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,027
git
# Partly cherry-picking a commit with Git I'm working on 2 different branches: **release** and **development**. I noticed I still need to integrate some changes that were committed to the **release** branch back into the **development** branch. The problem is I don't need all of the commit, only some hunks in certai...
The core thing you're going to want here is `git add -p` (`-p` is a synonym for `--patch`). This provides an interactive way to add in content, letting you decide whether each hunk should go in or not, and even letting you manually edit the patch if necessary. To use it in combination with cherry-pick: ``` git cherry...
4713088
How do I use git bisect?
767
2011-01-17 12:22:35
<p>I have read some articles saying that <a href="https://git-scm.com/docs/git-bisect" rel="noreferrer"><code>git bisect</code></a> is awesome. However, I can't understand why it's awesome.</p> <ol> <li>How do I use it?</li> <li>Is it just like <code>svn blame</code>?</li> </ol>
253,312
30,453
2025-05-13 01:19:23
4,714,297
1,021
2011-01-17 14:32:20
5,353
2022-11-23 14:40:52
https://stackoverflow.com/q/4713088
https://stackoverflow.com/a/4714297
<p>The idea behind <code>git bisect</code> is to perform a binary search in the history to find a particular regression. Imagine that you have the following development history:</p> <pre><code>... --- 0 --- 1 --- 2 --- 3 --- 4* --- 5 --- current </code></pre> <p>You know that your program is not working properly at the...
<p>The idea behind <code>git bisect</code> is to perform a binary search in the history to find a particular regression. Imagine that you have the following development history:</p> <pre><code>... --- 0 --- 1 --- 2 --- 3 --- 4* --- 5 --- current </code></pre> <p>You know that your program is not working properly at the...
119, 47326
git, git-bisect
<h1>How do I use git bisect?</h1> <p>I have read some articles saying that <a href="https://git-scm.com/docs/git-bisect" rel="noreferrer"><code>git bisect</code></a> is awesome. However, I can't understand why it's awesome.</p> <ol> <li>How do I use it?</li> <li>Is it just like <code>svn blame</code>?</li> </ol>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,028
git
# How do I use git bisect? I have read some articles saying that [`git bisect`](https://git-scm.com/docs/git-bisect) is awesome. However, I can't understand why it's awesome. 1. How do I use it? 2. Is it just like `svn blame`?
The idea behind `git bisect` is to perform a binary search in the history to find a particular regression. Imagine that you have the following development history: ``` ... --- 0 --- 1 --- 2 --- 3 --- 4* --- 5 --- current ``` You know that your program is not working properly at the `current` revision, and that it was...
21691202
How to create file execute mode permissions in Git on Windows?
706
2014-02-11 01:17:06
<p>I use Git in Windows, and want to push the executable shell script into git repo by one commit.</p> <p>Usually I need to do two steps (<code>git commit</code>).</p> <pre><code>$ vi install.sh $ git add install.sh $ git commit -am &quot;add new file for installation&quot; # first commit [master f2e92da] add support...
474,717
308,174
2023-03-12 15:54:55
21,694,391
1,019
2014-02-11 06:07:49
729,881
2014-02-11 06:07:49
https://stackoverflow.com/q/21691202
https://stackoverflow.com/a/21694391
<p>There's no need to do this in two commits, you can add the file and mark it executable in a single commit:</p> <pre><code>C:\Temp\TestRepo&gt;touch foo.sh C:\Temp\TestRepo&gt;git add foo.sh C:\Temp\TestRepo&gt;git ls-files --stage 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 foo.sh </code></pre> <p>As...
<p>There's no need to do this in two commits, you can add the file and mark it executable in a single commit:</p> <pre><code>C:\Temp\TestRepo&gt;touch foo.sh C:\Temp\TestRepo&gt;git add foo.sh C:\Temp\TestRepo&gt;git ls-files --stage 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 foo.sh </code></pre> <p>As...
64, 119, 359, 12380
chmod, git, permissions, windows
<h1>How to create file execute mode permissions in Git on Windows?</h1> <p>I use Git in Windows, and want to push the executable shell script into git repo by one commit.</p> <p>Usually I need to do two steps (<code>git commit</code>).</p> <pre><code>$ vi install.sh $ git add install.sh $ git commit -am &quot;add new...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,030
git
# How to create file execute mode permissions in Git on Windows? I use Git in Windows, and want to push the executable shell script into git repo by one commit. Usually I need to do two steps (`git commit`). ``` $ vi install.sh $ git add install.sh $ git commit -am "add new file for installation" # first commit [m...
There's no need to do this in two commits, you can add the file and mark it executable in a single commit: ``` C:\Temp\TestRepo>touch foo.sh C:\Temp\TestRepo>git add foo.sh C:\Temp\TestRepo>git ls-files --stage 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 foo.sh ``` As you note, after adding, the mode is...
45400361
Why is .gitignore not ignoring my files?
564
2017-07-30 13:35:05
<p>See the image below. My .gitignore file should be ignoring all files in src/dist, but isn't.</p> <p><a href="https://i.sstatic.net/1qVzG.png" rel="noreferrer"><img src="https://i.sstatic.net/1qVzG.png" alt="enter image description here"></a></p>
458,708
190,625
2024-11-09 13:03:24
45,400,404
1,016
2017-07-30 13:38:37
2,116,168
2017-07-30 14:13:37
https://stackoverflow.com/q/45400361
https://stackoverflow.com/a/45400404
<p><code>.gitignore</code> only ignores files that are not part of the repository yet. If you already <code>git add</code>ed some files, their changes will still be tracked. To remove those files from your repository (but not from your file system) use <code>git rm --cached</code> on them.</p>
<p><code>.gitignore</code> only ignores files that are not part of the repository yet. If you already <code>git add</code>ed some files, their changes will still be tracked. To remove those files from your repository (but not from your file system) use <code>git rm --cached</code> on them.</p>
119, 25056, 111608
git, gitignore, visual-studio-code
<h1>Why is .gitignore not ignoring my files?</h1> <p>See the image below. My .gitignore file should be ignoring all files in src/dist, but isn't.</p> <p><a href="https://i.sstatic.net/1qVzG.png" rel="noreferrer"><img src="https://i.sstatic.net/1qVzG.png" alt="enter image description here"></a></p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,031
git
# Why is .gitignore not ignoring my files? See the image below. My .gitignore file should be ignoring all files in src/dist, but isn't. [![enter image description here](https://i.sstatic.net/1qVzG.png)](https://i.sstatic.net/1qVzG.png)
`.gitignore` only ignores files that are not part of the repository yet. If you already `git add`ed some files, their changes will still be tracked. To remove those files from your repository (but not from your file system) use `git rm --cached` on them.
3211809
How to compare two tags with git?
603
2010-07-09 10:35:58
<p>I would like to do a diff between two tags and committed changes between those two tags. Could you please tell me the command?</p>
411,827
387,631
2023-01-04 17:50:22
3,211,829
1,013
2010-07-09 10:40:13
377,927
2021-03-23 05:42:39
https://stackoverflow.com/q/3211809
https://stackoverflow.com/a/3211829
<pre><code>$ git diff tag1 tag2 </code></pre> <p>or show log between them:</p> <pre><code>$ git log tag1..tag2 </code></pre> <p>sometimes it may be convenient to see only the list of files that were changed:</p> <pre><code>$ git diff tag1 tag2 --stat </code></pre> <p>and then look at the differences for some particular...
<pre><code>$ git diff tag1 tag2 </code></pre> <p>or show log between them:</p> <pre><code>$ git log tag1..tag2 </code></pre> <p>sometimes it may be convenient to see only the list of files that were changed:</p> <pre><code>$ git diff tag1 tag2 --stat </code></pre> <p>and then look at the differences for some particular...
119
git
<h1>How to compare two tags with git?</h1> <p>I would like to do a diff between two tags and committed changes between those two tags. Could you please tell me the command?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,032
git
# How to compare two tags with git? I would like to do a diff between two tags and committed changes between those two tags. Could you please tell me the command?
``` $ git diff tag1 tag2 ``` or show log between them: ``` $ git log tag1..tag2 ``` sometimes it may be convenient to see only the list of files that were changed: ``` $ git diff tag1 tag2 --stat ``` and then look at the differences for some particular file: ``` $ git diff tag1 tag2 -- some/file/name ``` A tag i...
4754152
How do I remove version tracking from a project cloned from git?
1,001
2011-01-21 00:12:09
<p>I want to remove all version tracking from a project's directory.</p> <p>What is the correct method to do this?</p> <p>Can I do a shell command such as:</p> <pre><code>rm -rf .git </code></pre> <p>from my projects directory or is there a way to do this as a Git command?</p> <p>I used this project to learn Git a...
1,169,808
69,738
2023-11-07 13:52:47
4,754,175
1,012
2011-01-21 00:15:56
144,846
2021-06-04 00:10:30
https://stackoverflow.com/q/4754152
https://stackoverflow.com/a/4754175
<p>All the data Git uses for information is stored in <code>.git/</code>, so removing it should work just fine. Of course, make sure that your working copy is in the exact state that you want it, because everything else will be lost. <code>.git</code> folder is hidden so make sure you turn on the &quot;Show hidden file...
<p>All the data Git uses for information is stored in <code>.git/</code>, so removing it should work just fine. Of course, make sure that your working copy is in the exact state that you want it, because everything else will be lost. <code>.git</code> folder is hidden so make sure you turn on the &quot;Show hidden file...
119, 96541
git, git-track
<h1>How do I remove version tracking from a project cloned from git?</h1> <p>I want to remove all version tracking from a project's directory.</p> <p>What is the correct method to do this?</p> <p>Can I do a shell command such as:</p> <pre><code>rm -rf .git </code></pre> <p>from my projects directory or is there a w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,033
git
# How do I remove version tracking from a project cloned from git? I want to remove all version tracking from a project's directory. What is the correct method to do this? Can I do a shell command such as: ``` rm -rf .git ``` from my projects directory or is there a way to do this as a Git command? I used this pr...
All the data Git uses for information is stored in `.git/`, so removing it should work just fine. Of course, make sure that your working copy is in the exact state that you want it, because everything else will be lost. `.git` folder is hidden so make sure you turn on the "Show hidden files, folders and disks" option. ...
3899627
Create Git branch with current changes
1,267
2010-10-10 08:44:12
<p>I started working on my <em>master</em> branch thinking that my task would be easy. After a while I realized it would take more work and I want to do all this work in a new branch. </p> <p>How can I create a new branch and take all these changes with me without dirtying <em>master</em>?</p>
888,909
51,382
2025-04-14 05:43:45
3,899,660
1,009
2010-10-10 08:52:37
6,309
2022-08-02 06:25:42
https://stackoverflow.com/q/3899627
https://stackoverflow.com/a/3899660
<p>If you hadn't made any commit yet, only (1: branch) and (3: checkout) would be enough.<br /> Or, in one command: <strong><code>git checkout -b newBranch</code></strong></p> <p>With <a href="https://stackoverflow.com/a/57066202/6309">Git 2.23+</a> (Q3 2019), the <a href="https://git-scm.com/docs/git-switch" rel="nore...
<p>If you hadn't made any commit yet, only (1: branch) and (3: checkout) would be enough.<br /> Or, in one command: <strong><code>git checkout -b newBranch</code></strong></p> <p>With <a href="https://stackoverflow.com/a/57066202/6309">Git 2.23+</a> (Q3 2019), the <a href="https://git-scm.com/docs/git-switch" rel="nore...
119, 76220
git, git-branch
<h1>Create Git branch with current changes</h1> <p>I started working on my <em>master</em> branch thinking that my task would be easy. After a while I realized it would take more work and I want to do all this work in a new branch. </p> <p>How can I create a new branch and take all these changes with me without dirty...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,034
git
# Create Git branch with current changes I started working on my *master* branch thinking that my task would be easy. After a while I realized it would take more work and I want to do all this work in a new branch. How can I create a new branch and take all these changes with me without dirtying *master*?
If you hadn't made any commit yet, only (1: branch) and (3: checkout) would be enough. Or, in one command: **`git checkout -b newBranch`** With [Git 2.23+](https://stackoverflow.com/a/57066202/6309) (Q3 2019), the [new command `git switch`](https://git-scm.com/docs/git-switch) would create the branch in one line (wi...
466764
Git command to show which specific files are ignored by .gitignore
896
2009-01-21 20:09:36
<p>I am getting my feet wet with Git and have the following issue:</p> <p>My project source tree:</p> <pre><code>/ | +--src/ +----refs/ +----... | +--vendor/ +----... </code></pre> <p>I have code (currently MEF) in my vendor branch that I will compile there and then move the references into <code>/src/refs</code> wh...
582,834
3,683
2024-03-03 11:27:43
467,053
1,009
2009-01-21 21:17:24
6,309
2024-03-03 11:27:43
https://stackoverflow.com/q/466764
https://stackoverflow.com/a/467053
<p>Notes:</p> <ul> <li>xiaobai's <a href="https://stackoverflow.com/questions/466764/git-command-to-show-which-specific-files-are-ignored-by-gitignore/12080920#12080920">answer</a> is simpler (git1.7.6+): <code>git status --ignored</code> (as detailed in &quot;<a href="https://stackoverflow.com/questions/2994612/is-the...
<p>Notes:</p> <ul> <li>xiaobai's <a href="https://stackoverflow.com/questions/466764/git-command-to-show-which-specific-files-are-ignored-by-gitignore/12080920#12080920">answer</a> is simpler (git1.7.6+): <code>git status --ignored</code> (as detailed in &quot;<a href="https://stackoverflow.com/questions/2994612/is-the...
119, 4333
git, ignore
<h1>Git command to show which specific files are ignored by .gitignore</h1> <p>I am getting my feet wet with Git and have the following issue:</p> <p>My project source tree:</p> <pre><code>/ | +--src/ +----refs/ +----... | +--vendor/ +----... </code></pre> <p>I have code (currently MEF) in my vendor branch that I wi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,035
git
# Git command to show which specific files are ignored by .gitignore I am getting my feet wet with Git and have the following issue: My project source tree: ``` / | +--src/ +----refs/ +----... | +--vendor/ +----... ``` I have code (currently MEF) in my vendor branch that I will compile there and then move the refer...
Notes: - xiaobai's [answer](https://stackoverflow.com/questions/466764/git-command-to-show-which-specific-files-are-ignored-by-gitignore/12080920#12080920) is simpler (git1.7.6+): `git status --ignored` (as detailed in "[Is there a way to tell git-status to ignore the effects of `.gitignore` files?](https://stackove...
556923
How do I merge my local uncommitted changes into another Git branch?
718
2009-02-17 14:02:16
<p>How can I do the following in Git?</p> <p>My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a way to apply/merge these changes so that they become local changes on branch2 without committing them on branch1...
164,784
67,378
2023-10-26 13:01:11
556,986
1,004
2009-02-17 14:16:07
6,309
2021-11-14 16:05:35
https://stackoverflow.com/q/556923
https://stackoverflow.com/a/556986
<p>Since your files are not yet committed in <code>branch1</code>:</p> <pre><code>git stash git checkout branch2 git stash pop </code></pre> <p>or</p> <pre><code>git stash git checkout branch2 git stash list # to check the various stash made in different branch git stash apply x # to select the right one </cod...
<p>Since your files are not yet committed in <code>branch1</code>:</p> <pre><code>git stash git checkout branch2 git stash pop </code></pre> <p>or</p> <pre><code>git stash git checkout branch2 git stash list # to check the various stash made in different branch git stash apply x # to select the right one </cod...
119, 1879
branch, git
<h1>How do I merge my local uncommitted changes into another Git branch?</h1> <p>How can I do the following in Git?</p> <p>My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a way to apply/merge these changes s...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,036
git
# How do I merge my local uncommitted changes into another Git branch? How can I do the following in Git? My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a way to apply/merge these changes so that they beco...
Since your files are not yet committed in `branch1`: ``` git stash git checkout branch2 git stash pop ``` or ``` git stash git checkout branch2 git stash list # to check the various stash made in different branch git stash apply x # to select the right one ``` Above is the longer more explicit version of [...
10523849
How do you change the capitalization of filenames in Git?
762
2012-05-09 20:46:51
<p>I am trying to rename a file to have different capitalization from what it had before:</p> <pre><code>git mv src/collision/b2AABB.js src/collision/B2AABB.js fatal: destination exists, source=src/collision/b2AABB.js, destination=src/collision/B2AABB.js </code></pre> <p>As you can see, Git throws a fit over this. I tr...
354,621
355,325
2024-08-09 19:51:54
24,979,063
1,001
2014-07-27 08:00:46
6,309
2024-08-09 19:51:54
https://stackoverflow.com/q/10523849
https://stackoverflow.com/a/24979063
<p>Starting Git 2.0.1 (June 25th, 2014), a <strong><code>git mv</code> will just work on a case-insensitive OS</strong>.</p> <p>See <a href="https://github.com/git/git/commit/baa37bff9a845471754d3f47957d58a6ccc30058" rel="noreferrer">commit baa37bf</a> by <a href="https://github.com/dturner-tw" rel="noreferrer">David T...
<p>Starting Git 2.0.1 (June 25th, 2014), a <strong><code>git mv</code> will just work on a case-insensitive OS</strong>.</p> <p>See <a href="https://github.com/git/git/commit/baa37bff9a845471754d3f47957d58a6ccc30058" rel="noreferrer">commit baa37bf</a> by <a href="https://github.com/dturner-tw" rel="noreferrer">David T...
119, 4510, 9708, 12895
case-sensitive, file-rename, git, rename
<h1>How do you change the capitalization of filenames in Git?</h1> <p>I am trying to rename a file to have different capitalization from what it had before:</p> <pre><code>git mv src/collision/b2AABB.js src/collision/B2AABB.js fatal: destination exists, source=src/collision/b2AABB.js, destination=src/collision/B2AABB.j...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,037
git
# How do you change the capitalization of filenames in Git? I am trying to rename a file to have different capitalization from what it had before: ``` git mv src/collision/b2AABB.js src/collision/B2AABB.js fatal: destination exists, source=src/collision/b2AABB.js, destination=src/collision/B2AABB.js ``` As you can s...
Starting Git 2.0.1 (June 25th, 2014), a **`git mv` will just work on a case-insensitive OS**. See [commit baa37bf](https://github.com/git/git/commit/baa37bff9a845471754d3f47957d58a6ccc30058) by [David Turner (`dturner-tw`)](https://github.com/dturner-tw). ### `mv`: allow renaming to fix case on case-insensitive files...
6632191
How to revert initial git commit?
637
2011-07-09 01:49:42
<p>I commit to a git repository for the first time; I then regret the commit and want to revert it. I try</p> <pre><code># git reset --hard HEAD~1 </code></pre> <p>I get this message:</p> <pre><code>fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree. </code></pre> <p>This commit i...
248,722
186,849
2023-09-12 07:56:16
6,637,891
1,001
2011-07-09 22:26:23
19,563
2011-07-09 22:26:23
https://stackoverflow.com/q/6632191
https://stackoverflow.com/a/6637891
<p>You just need to delete the branch you are on. You can't use <code>git branch -D</code> as this has a safety check against doing this. You can use <code>update-ref</code> to do this.</p> <pre><code>git update-ref -d HEAD </code></pre> <p>Do <em>not</em> use <code>rm -rf .git</code> or anything like this as this wi...
<p>You just need to delete the branch you are on. You can't use <code>git branch -D</code> as this has a safety check against doing this. You can use <code>update-ref</code> to do this.</p> <pre><code>git update-ref -d HEAD </code></pre> <p>Do <em>not</em> use <code>rm -rf .git</code> or anything like this as this wi...
119
git
<h1>How to revert initial git commit?</h1> <p>I commit to a git repository for the first time; I then regret the commit and want to revert it. I try</p> <pre><code># git reset --hard HEAD~1 </code></pre> <p>I get this message:</p> <pre><code>fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the wo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,038
git
# How to revert initial git commit? I commit to a git repository for the first time; I then regret the commit and want to revert it. I try ``` # git reset --hard HEAD~1 ``` I get this message: ``` fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree. ``` This commit is the first com...
You just need to delete the branch you are on. You can't use `git branch -D` as this has a safety check against doing this. You can use `update-ref` to do this. ``` git update-ref -d HEAD ``` Do *not* use `rm -rf .git` or anything like this as this will completely wipe your entire repository including all other branc...
10039747
How to view file diff in git before commit
624
2012-04-06 06:03:10
<p>This often happens to me: </p> <p>I'm working on a couple related changes at the same time over the course of a day or two, and when it's time to commit, I end up forgetting what changed in a specific file. (This is just a personal git repo, so I'm ok with having more than one update in a commit.) </p> <p>Is there...
699,704
709,271
2025-08-27 10:05:29
10,039,758
1,000
2012-04-06 06:04:54
148,870
2025-08-27 10:05:29
https://stackoverflow.com/q/10039747
https://stackoverflow.com/a/10039758
<p>If you want to display changes you have <strong>not <a href="https://git-scm.com/about/staging-area" rel="noreferrer">staged</a></strong> yet:</p> <pre><code>git diff myfile.txt </code></pre> <p>If you want to see <strong>only those in the index</strong> (those which you already <a href="https://git-scm.com/docs/git...
<p>If you want to display changes you have <strong>not <a href="https://git-scm.com/about/staging-area" rel="noreferrer">staged</a></strong> yet:</p> <pre><code>git diff myfile.txt </code></pre> <p>If you want to see <strong>only those in the index</strong> (those which you already <a href="https://git-scm.com/docs/git...
119, 9033
git, git-diff
<h1>How to view file diff in git before commit</h1> <p>This often happens to me: </p> <p>I'm working on a couple related changes at the same time over the course of a day or two, and when it's time to commit, I end up forgetting what changed in a specific file. (This is just a personal git repo, so I'm ok with having ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,039
git
# How to view file diff in git before commit This often happens to me: I'm working on a couple related changes at the same time over the course of a day or two, and when it's time to commit, I end up forgetting what changed in a specific file. (This is just a personal git repo, so I'm ok with having more than one upd...
If you want to display changes you have **not [staged](https://git-scm.com/about/staging-area)** yet: ``` git diff myfile.txt ``` If you want to see **only those in the index** (those which you already [`add`](https://git-scm.com/docs/git-add)ed): ``` git diff --cached myfile.txt ```
5423517
How do I push a local Git branch to master branch in the remote?
582
2011-03-24 18:07:50
<p>I have a branch called develop in my local repo, and I want to make sure that when I push it to origin it's merged with the origin/master. Currently, when I push it's added to a remote develop branch. </p> <p>How can I do this?</p>
797,345
32,816
2023-06-30 13:46:55
5,423,655
1,000
2011-03-24 18:21:18
28,804
2016-01-26 18:33:01
https://stackoverflow.com/q/5423517
https://stackoverflow.com/a/5423655
<pre><code>$ git push origin develop:master </code></pre> <p>or, more generally</p> <pre><code>$ git push &lt;remote&gt; &lt;local branch name&gt;:&lt;remote branch to push into&gt; </code></pre>
<pre><code>$ git push origin develop:master </code></pre> <p>or, more generally</p> <pre><code>$ git push &lt;remote&gt; &lt;local branch name&gt;:&lt;remote branch to push into&gt; </code></pre>
119, 18556, 28898, 76220
git, git-branch, git-push, remote-server
<h1>How do I push a local Git branch to master branch in the remote?</h1> <p>I have a branch called develop in my local repo, and I want to make sure that when I push it to origin it's merged with the origin/master. Currently, when I push it's added to a remote develop branch. </p> <p>How can I do this?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,040
git
# How do I push a local Git branch to master branch in the remote? I have a branch called develop in my local repo, and I want to make sure that when I push it to origin it's merged with the origin/master. Currently, when I push it's added to a remote develop branch. How can I do this?
``` $ git push origin develop:master ``` or, more generally ``` $ git push <remote> <local branch name>:<remote branch to push into> ```
2304087
What is HEAD in Git?
1,386
2010-02-20 22:58:13
<p>You see the Git documentation saying things like</p> <blockquote> <p>The branch must be fully merged in HEAD.</p> </blockquote> <p>But what is Git <code>HEAD</code> exactly?</p>
796,910
111,307
2024-04-27 09:24:45
2,304,106
999
2010-02-20 23:00:49
893
2010-02-20 23:00:49
https://stackoverflow.com/q/2304087
https://stackoverflow.com/a/2304106
<p>You can think of the HEAD as the "current branch". When you switch branches with <code>git checkout</code>, the HEAD revision changes to point to the tip of the new branch.</p> <p>You can see what HEAD points to by doing:</p> <pre><code>cat .git/HEAD </code></pre> <p>In my case, the output is:</p> <pre><code>$ c...
<p>You can think of the HEAD as the "current branch". When you switch branches with <code>git checkout</code>, the HEAD revision changes to point to the tip of the new branch.</p> <p>You can see what HEAD points to by doing:</p> <pre><code>cat .git/HEAD </code></pre> <p>In my case, the output is:</p> <pre><code>$ c...
119
git
<h1>What is HEAD in Git?</h1> <p>You see the Git documentation saying things like</p> <blockquote> <p>The branch must be fully merged in HEAD.</p> </blockquote> <p>But what is Git <code>HEAD</code> exactly?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,041
git
# What is HEAD in Git? You see the Git documentation saying things like > The branch must be fully merged in HEAD. But what is Git `HEAD` exactly?
You can think of the HEAD as the "current branch". When you switch branches with `git checkout`, the HEAD revision changes to point to the tip of the new branch. You can see what HEAD points to by doing: ``` cat .git/HEAD ``` In my case, the output is: ``` $ cat .git/HEAD ref: refs/heads/master ``` It is possible ...
2246208
Change first commit of project with Git?
662
2010-02-11 17:17:53
<p>I want to change something in the first commit of my project with out losing all subsequent commits. Is there any way to do this?</p> <p>I accidentally listed my raw email in a comment within the source code, and I'd like to change it as I'm getting spammed from bots indexing GitHub.</p>
213,006
217,476
2025-07-20 09:43:01
2,309,391
996
2010-02-22 07:20:36
6,309
2025-07-20 09:43:01
https://stackoverflow.com/q/2246208
https://stackoverflow.com/a/2309391
<p>As mentioned by <a href="https://stackoverflow.com/users/656927/ecdpalma">ecdpalma</a> <a href="https://stackoverflow.com/a/14629246/6309">below</a>, <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.12.adoc" rel="noreferrer">git 1.7.12+</a> (August 2012) has enhanced the option <code>--root...
<p>As mentioned by <a href="https://stackoverflow.com/users/656927/ecdpalma">ecdpalma</a> <a href="https://stackoverflow.com/a/14629246/6309">below</a>, <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.12.adoc" rel="noreferrer">git 1.7.12+</a> (August 2012) has enhanced the option <code>--root...
119, 8974, 46509
git, git-filter-branch, rebase
<h1>Change first commit of project with Git?</h1> <p>I want to change something in the first commit of my project with out losing all subsequent commits. Is there any way to do this?</p> <p>I accidentally listed my raw email in a comment within the source code, and I'd like to change it as I'm getting spammed from bot...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,043
git
# Change first commit of project with Git? I want to change something in the first commit of my project with out losing all subsequent commits. Is there any way to do this? I accidentally listed my raw email in a comment within the source code, and I'd like to change it as I'm getting spammed from bots indexing GitHu...
As mentioned by [ecdpalma](https://stackoverflow.com/users/656927/ecdpalma) [below](https://stackoverflow.com/a/14629246/6309), [git 1.7.12+](https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.12.adoc) (August 2012) has enhanced the option `--root` for `git rebase`: "`git rebase [-i] --root $tip`" can n...
598672
Squash the first two commits in Git?
712
2009-02-28 20:55:09
<p>With <code>git rebase --interactive &lt;commit&gt;</code> you can squash any number of commits together into a single one.</p> <p>That's all great unless you want to squash commits into the initial commit. That seems impossible to do.</p> <p>Are there any ways to achieve it?</p> <hr> <h3>Moderately related:</h3>...
222,040
13,989
2022-12-31 11:19:24
598,788
994
2009-02-28 22:18:47
6,309
2022-12-31 11:19:24
https://stackoverflow.com/q/598672
https://stackoverflow.com/a/598788
<p>Update July 2012 (<a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.12.txt#L59" rel="noreferrer">git 1.7.12+</a>)</p> <p>You now can rebase all commits up to root, and select the second commit <code>Y</code> to be squashed with the first <code>X</code>.</p> <pre><code>git rebase -i --root ma...
<p>Update July 2012 (<a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.12.txt#L59" rel="noreferrer">git 1.7.12+</a>)</p> <p>You now can rebase all commits up to root, and select the second commit <code>Y</code> to be squashed with the first <code>X</code>.</p> <pre><code>git rebase -i --root ma...
119, 8974, 29934, 42532
git, git-rebase, rebase, squash
<h1>Squash the first two commits in Git?</h1> <p>With <code>git rebase --interactive &lt;commit&gt;</code> you can squash any number of commits together into a single one.</p> <p>That's all great unless you want to squash commits into the initial commit. That seems impossible to do.</p> <p>Are there any ways to achie...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,044
git
# Squash the first two commits in Git? With `git rebase --interactive <commit>` you can squash any number of commits together into a single one. That's all great unless you want to squash commits into the initial commit. That seems impossible to do. Are there any ways to achieve it? --- ### Moderately related: In...
Update July 2012 ([git 1.7.12+](https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.12.txt#L59)) You now can rebase all commits up to root, and select the second commit `Y` to be squashed with the first `X`. ``` git rebase -i --root master pick sha1 X squash sha1 Y pick sha1 Z ``` > ``` > git rebase [...
22992543
How do I git rebase the first commit?
578
2014-04-10 15:35:09
<p>I used <code>git init</code> to create a fresh repo, then made three commits. Now I want to rebase to go back and amend my first commit, but if I do <code>git rebase -i HEAD~3</code> it shows error - <code>fatal: invalid upstream 'HEAD~3'</code>!</p> <p>If I try the same with <code>HEAD~2</code> then it kinda works ...
149,673
304,282
2022-11-11 11:33:33
23,000,315
990
2014-04-10 22:35:15
1,256,452
2022-08-31 22:22:29
https://stackoverflow.com/q/22992543
https://stackoverflow.com/a/23000315
<p>The easy way, with a recent-enough Git (this has been out for a long time now so you should have this):</p> <pre><code>git rebase -i --root </code></pre> <p>The other easy way, as <a href="https://stackoverflow.com/users/1253222/twalberg">twalberg</a> noted in a comment that has since been deleted but is now expande...
<p>The easy way, with a recent-enough Git (this has been out for a long time now so you should have this):</p> <pre><code>git rebase -i --root </code></pre> <p>The other easy way, as <a href="https://stackoverflow.com/users/1253222/twalberg">twalberg</a> noted in a comment that has since been deleted but is now expande...
119, 29934
git, git-rebase
<h1>How do I git rebase the first commit?</h1> <p>I used <code>git init</code> to create a fresh repo, then made three commits. Now I want to rebase to go back and amend my first commit, but if I do <code>git rebase -i HEAD~3</code> it shows error - <code>fatal: invalid upstream 'HEAD~3'</code>!</p> <p>If I try the sam...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,045
git
# How do I git rebase the first commit? I used `git init` to create a fresh repo, then made three commits. Now I want to rebase to go back and amend my first commit, but if I do `git rebase -i HEAD~3` it shows error - `fatal: invalid upstream 'HEAD~3'`! If I try the same with `HEAD~2` then it kinda works but only let...
The easy way, with a recent-enough Git (this has been out for a long time now so you should have this): ``` git rebase -i --root ``` The other easy way, as [twalberg](https://stackoverflow.com/users/1253222/twalberg) noted in a comment that has since been deleted but is now expanded in [https://stackoverflow.com/a/68...
1777854
How can I specify a branch/tag when adding a Git submodule?
1,199
2009-11-22 04:55:48
<p>How does <code>git submodule add -b</code> work?</p> <p>After adding a submodule with a specific branch, a new cloned repository (after <code>git submodule update --init</code>) will be at a specific commit, not the branch itself (<code>git status</code> on the submodule shows &quot;Not currently on any branch&quot;...
1,186,184
16,957
2024-04-05 03:40:57
1,778,247
986
2009-11-22 09:19:34
420,098
2019-07-02 21:43:08
https://stackoverflow.com/q/1777854
https://stackoverflow.com/a/1778247
<p>Note: Git 1.8.2 added the possibility to track branches. See some of the answers below.</p> <hr> <p>It's a little confusing to get used to this, but submodules are not on a branch. They are, like you say, just a pointer to a particular commit of the submodule's repository.</p> <p>This means, when someone else ch...
<p>Note: Git 1.8.2 added the possibility to track branches. See some of the answers below.</p> <hr> <p>It's a little confusing to get used to this, but submodules are not on a branch. They are, like you say, just a pointer to a particular commit of the submodule's repository.</p> <p>This means, when someone else ch...
119, 41612
git, git-submodules
<h1>How can I specify a branch/tag when adding a Git submodule?</h1> <p>How does <code>git submodule add -b</code> work?</p> <p>After adding a submodule with a specific branch, a new cloned repository (after <code>git submodule update --init</code>) will be at a specific commit, not the branch itself (<code>git status<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,047
git
# How can I specify a branch/tag when adding a Git submodule? How does `git submodule add -b` work? After adding a submodule with a specific branch, a new cloned repository (after `git submodule update --init`) will be at a specific commit, not the branch itself (`git status` on the submodule shows "Not currently on ...
Note: Git 1.8.2 added the possibility to track branches. See some of the answers below. --- It's a little confusing to get used to this, but submodules are not on a branch. They are, like you say, just a pointer to a particular commit of the submodule's repository. This means, when someone else checks out your repos...
1064361
Unable to show a Git tree in terminal
563
2009-06-30 15:30:44
<p><a href="http://killswitchcollective.com/articles/36_git_it_got_it_good" rel="noreferrer">Killswitchcollective.com's old article, 30 June 2009</a>, has the following inputs and outputs</p> <pre><code>git co master git merge [your_branch] git push upstream A-B-C-D-E A-B-C-D-E-F-G \ ...
509,198
54,964
2019-03-12 17:34:09
1,064,431
986
2009-06-30 15:41:57
6,309
2016-04-11 16:24:19
https://stackoverflow.com/q/1064361
https://stackoverflow.com/a/1064431
<p>How can you get the tree-like view of commits in terminal?</p> <pre><code>git log --graph --oneline --all </code></pre> <p>is a good start.</p> <p>You may get some strange letters. They are ASCII codes for colors and structure. To solve this problem add the following to your <code>.bashrc</code>:</p> <pre><code>...
<p>How can you get the tree-like view of commits in terminal?</p> <pre><code>git log --graph --oneline --all </code></pre> <p>is a good start.</p> <p>You may get some strange letters. They are ASCII codes for colors and structure. To solve this problem add the following to your <code>.bashrc</code>:</p> <pre><code>...
119, 391, 488, 572, 69559
console, git, revision-history, terminal, tree
<h1>Unable to show a Git tree in terminal</h1> <p><a href="http://killswitchcollective.com/articles/36_git_it_got_it_good" rel="noreferrer">Killswitchcollective.com's old article, 30 June 2009</a>, has the following inputs and outputs</p> <pre><code>git co master git merge [your_branch] git push upstream A-B-C-D-E...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,048
git
# Unable to show a Git tree in terminal [Killswitchcollective.com's old article, 30 June 2009](http://killswitchcollective.com/articles/36_git_it_got_it_good), has the following inputs and outputs ``` git co master git merge [your_branch] git push upstream A-B-C-D-E A-B-C-D-E-F-G \ ...
How can you get the tree-like view of commits in terminal? ``` git log --graph --oneline --all ``` is a good start. You may get some strange letters. They are ASCII codes for colors and structure. To solve this problem add the following to your `.bashrc`: ``` export LESS="-R" ``` such that you do not need use Tig'...
8048584
See changes to a specific file using git
769
2011-11-08 09:55:06
<p>I know that I can use the <code>git diff</code> command to check the changes, but, as far as I understood, it is directory based. This means it gives all the changes of all files on the current directory.</p> <p><em>How can I check only the changes in one specific file?</em> Say, I have changed files <code>file_1.r...
897,509
475,850
2023-06-29 10:23:24
8,048,608
985
2011-11-08 09:56:39
893
2023-03-12 23:46:59
https://stackoverflow.com/q/8048584
https://stackoverflow.com/a/8048608
<p>Use a command like:</p> <pre><code>git diff file_2.rb </code></pre> <p>See the <a href="https://git-scm.com/docs/git-diff" rel="noreferrer"><code>git diff</code> documentation</a> for full information on the kinds of things you can get differences for.</p> <p>Normally, <code>git diff</code> by itself shows all the c...
<p>Use a command like:</p> <pre><code>git diff file_2.rb </code></pre> <p>See the <a href="https://git-scm.com/docs/git-diff" rel="noreferrer"><code>git diff</code> documentation</a> for full information on the kinds of things you can get differences for.</p> <p>Normally, <code>git diff</code> by itself shows all the c...
119, 6452
git, git-svn
<h1>See changes to a specific file using git</h1> <p>I know that I can use the <code>git diff</code> command to check the changes, but, as far as I understood, it is directory based. This means it gives all the changes of all files on the current directory.</p> <p><em>How can I check only the changes in one specific f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,050
git
# See changes to a specific file using git I know that I can use the `git diff` command to check the changes, but, as far as I understood, it is directory based. This means it gives all the changes of all files on the current directory. *How can I check only the changes in one specific file?* Say, I have changed file...
Use a command like: ``` git diff file_2.rb ``` See the [`git diff` documentation](https://git-scm.com/docs/git-diff) for full information on the kinds of things you can get differences for. Normally, `git diff` by itself shows all the changes in the whole *repository* (not just the current directory).
9229301
git cherry-pick says "...38c74d is a merge but no -m option was given"
944
2012-02-10 14:26:50
<p>I made some changes in my master branch and want to bring those upstream. When I cherry-pick the following commits. However, I get stuck on fd9f578 where git says:</p> <pre><code>$ git cherry-pick fd9f578 fatal: Commit fd9f57850f6b94b7906e5bbe51a0d75bf638c74d is a merge but no -m option was given. </code></pre> <p>W...
782,103
566,145
2024-02-09 01:00:17
9,229,393
983
2012-02-10 14:34:53
383,402
2023-09-28 19:18:14
https://stackoverflow.com/q/9229301
https://stackoverflow.com/a/9229393
<p>The way a cherry-pick works is by taking the diff a changeset represents (the difference between the working tree at that point and the working tree of its parent), and applying it to your current branch.</p> <p>So, if a commit has two or more parents, it also represents two or more diffs - which one should be appli...
<p>The way a cherry-pick works is by taking the diff a changeset represents (the difference between the working tree at that point and the working tree of its parent), and applying it to your current branch.</p> <p>So, if a commit has two or more parents, it also represents two or more diffs - which one should be appli...
119, 717, 8974, 36489, 78810
cherry-pick, git, git-cherry-pick, merge, rebase
<h1>git cherry-pick says "...38c74d is a merge but no -m option was given"</h1> <p>I made some changes in my master branch and want to bring those upstream. When I cherry-pick the following commits. However, I get stuck on fd9f578 where git says:</p> <pre><code>$ git cherry-pick fd9f578 fatal: Commit fd9f57850f6b94b790...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,052
git
# git cherry-pick says "...38c74d is a merge but no -m option was given" I made some changes in my master branch and want to bring those upstream. When I cherry-pick the following commits. However, I get stuck on fd9f578 where git says: ``` $ git cherry-pick fd9f578 fatal: Commit fd9f57850f6b94b7906e5bbe51a0d75bf638c...
The way a cherry-pick works is by taking the diff a changeset represents (the difference between the working tree at that point and the working tree of its parent), and applying it to your current branch. So, if a commit has two or more parents, it also represents two or more diffs - which one should be applied? You'...
9839083
Git number of commits per author on all branches
483
2012-03-23 12:20:26
<p>I'd like to get the number of commits per author on all branches. I see that</p> <pre><code>git shortlog -s -n </code></pre> <p>Prints a very nice list but it is not counting the commits that are not yet merged from other branches. If iterate this command over every branch then obviously the common commits get cou...
184,245
487,534
2024-04-26 19:58:10
9,839,491
972
2012-03-23 12:48:13
106,205
2023-06-20 08:09:46
https://stackoverflow.com/q/9839083
https://stackoverflow.com/a/9839491
<pre class="lang-bash prettyprint-override"><code>git shortlog --summary --numbered --all --no-merges </code></pre> <p>Will give you statistics for all branches.</p> <p><strong>EDIT</strong>: Added <code>--no-merges</code> to exclude statistics from merge commits.</p>
<pre class="lang-bash prettyprint-override"><code>git shortlog --summary --numbered --all --no-merges </code></pre> <p>Will give you statistics for all branches.</p> <p><strong>EDIT</strong>: Added <code>--no-merges</code> to exclude statistics from merge commits.</p>
119, 456, 5597
commit, git, version-control
<h1>Git number of commits per author on all branches</h1> <p>I'd like to get the number of commits per author on all branches. I see that</p> <pre><code>git shortlog -s -n </code></pre> <p>Prints a very nice list but it is not counting the commits that are not yet merged from other branches. If iterate this command o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,053
git
# Git number of commits per author on all branches I'd like to get the number of commits per author on all branches. I see that ``` git shortlog -s -n ``` Prints a very nice list but it is not counting the commits that are not yet merged from other branches. If iterate this command over every branch then obviously t...
``` git shortlog --summary --numbered --all --no-merges ``` Will give you statistics for all branches. **EDIT**: Added `--no-merges` to exclude statistics from merge commits.
10168449
Git update submodules recursively
454
2012-04-16 03:38:57
<p>My project struture</p> <pre><code>ProjectA -FrameworkA (submodule) --Twig (submodule of FrameworkA) </code></pre> <p>How I can update submodules recursively? I already tried some git commands (on ProjectA root)</p> <pre><code>git submodule foreach git pull origin master </code></pre> <p>or</p> <pre><code>git s...
706,801
441,493
2023-07-19 13:05:59
10,168,693
972
2012-04-16 04:24:10
661,853
2019-07-17 18:51:41
https://stackoverflow.com/q/10168449
https://stackoverflow.com/a/10168693
<pre><code>git submodule update --recursive </code></pre> <p>You will also probably want to use the --init option which will make it initialize any uninitialized submodules:</p> <pre><code>git submodule update --init --recursive </code></pre> <p><em>Note: <strong>in some older versions of Git</strong>, if you use th...
<pre><code>git submodule update --recursive </code></pre> <p>You will also probably want to use the --init option which will make it initialize any uninitialized submodules:</p> <pre><code>git submodule update --init --recursive </code></pre> <p><em>Note: <strong>in some older versions of Git</strong>, if you use th...
119, 41612
git, git-submodules
<h1>Git update submodules recursively</h1> <p>My project struture</p> <pre><code>ProjectA -FrameworkA (submodule) --Twig (submodule of FrameworkA) </code></pre> <p>How I can update submodules recursively? I already tried some git commands (on ProjectA root)</p> <pre><code>git submodule foreach git pull origin master...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,054
git
# Git update submodules recursively My project struture ``` ProjectA -FrameworkA (submodule) --Twig (submodule of FrameworkA) ``` How I can update submodules recursively? I already tried some git commands (on ProjectA root) ``` git submodule foreach git pull origin master ``` or ``` git submodule foreach --recurs...
``` git submodule update --recursive ``` You will also probably want to use the --init option which will make it initialize any uninitialized submodules: ``` git submodule update --init --recursive ``` *Note: **in some older versions of Git**, if you use the `--init` option, already-initialized submodules may not be...
16820852
How to abort a cherry-pick?
621
2013-05-29 18:01:01
<p>I ran <code>git cherry-pick &lt;hash&gt;</code> and had merge conflicts. I don't want to resolve the conflicts, I just want to abort the cherry-pick. When doing an actual merge (with <code>git merge</code>) there's the handy <code>git merge --abort</code>. What's the equivalent of cherry-picking?</p>
377,645
836,205
2022-05-26 09:32:05
16,826,728
967
2013-05-30 01:54:06
null
2014-07-28 07:54:09
https://stackoverflow.com/q/16820852
https://stackoverflow.com/a/16826728
<p>You can do the following</p> <pre><code>git cherry-pick --abort </code></pre> <p>From the <a href="http://jk.gs/git-cherry-pick.html"><code>git cherry-pick</code> docs</a></p> <blockquote> <pre><code>--abort </code></pre> <p>Cancel the operation and return to the pre-sequence state.</p> </blockquote>
<p>You can do the following</p> <pre><code>git cherry-pick --abort </code></pre> <p>From the <a href="http://jk.gs/git-cherry-pick.html"><code>git cherry-pick</code> docs</a></p> <blockquote> <pre><code>--abort </code></pre> <p>Cancel the operation and return to the pre-sequence state.</p> </blockquote>
119, 78810
git, git-cherry-pick
<h1>How to abort a cherry-pick?</h1> <p>I ran <code>git cherry-pick &lt;hash&gt;</code> and had merge conflicts. I don't want to resolve the conflicts, I just want to abort the cherry-pick. When doing an actual merge (with <code>git merge</code>) there's the handy <code>git merge --abort</code>. What's the equivalent o...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,055
git
# How to abort a cherry-pick? I ran `git cherry-pick <hash>` and had merge conflicts. I don't want to resolve the conflicts, I just want to abort the cherry-pick. When doing an actual merge (with `git merge`) there's the handy `git merge --abort`. What's the equivalent of cherry-picking?
You can do the following ``` git cherry-pick --abort ``` From the [`git cherry-pick` docs](http://jk.gs/git-cherry-pick.html) > ``` > --abort > ``` > > Cancel the operation and return to the pre-sequence state.
8515729
How to abort a stash pop?
653
2011-12-15 05:54:27
<p>I popped a stash and there was a merge conflict. Unlike the question that is listed as a duplicate, I already had some uncommitted changes in the directory which I wanted to keep. I don't just want to make the merge conflict disappear, but also to get my directory back to the state it was before the pop.</p> <p>I t...
339,055
165,495
2025-11-13 16:49:23
60,444,590
963
2020-02-28 02:52:30
4,271,922
2025-11-13 16:49:23
https://stackoverflow.com/q/8515729
https://stackoverflow.com/a/60444590
<h1>Simple one liner</h1> <p>I have always used</p> <p><code>git reset --merge</code></p> <p>I can't remember it ever failing.</p> <hr /> <p><sub>Note: <code>git reset --merge</code> will discard any staged changes. Also, as noted by @Saroopashree Kumaraguru in the comments, the stash contents won't be lost and can be ...
<h1>Simple one liner</h1> <p>I have always used</p> <p><code>git reset --merge</code></p> <p>I can't remember it ever failing.</p> <hr /> <p><sub>Note: <code>git reset --merge</code> will discard any staged changes. Also, as noted by @Saroopashree Kumaraguru in the comments, the stash contents won't be lost and can be ...
119, 13091, 51381, 106113
git, git-merge-conflict, git-reset, git-stash
<h1>How to abort a stash pop?</h1> <p>I popped a stash and there was a merge conflict. Unlike the question that is listed as a duplicate, I already had some uncommitted changes in the directory which I wanted to keep. I don't just want to make the merge conflict disappear, but also to get my directory back to the state...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,056
git
# How to abort a stash pop? I popped a stash and there was a merge conflict. Unlike the question that is listed as a duplicate, I already had some uncommitted changes in the directory which I wanted to keep. I don't just want to make the merge conflict disappear, but also to get my directory back to the state it was b...
# Simple one liner I have always used `git reset --merge` I can't remember it ever failing. --- Note: `git reset --merge` will discard any staged changes. Also, as noted by @Saroopashree Kumaraguru in the comments, the stash contents won't be lost and can be re-applied later.
21277806
fatal: early EOF fatal: index-pack failed
580
2014-01-22 08:32:17
<p>I have googled and found many solutions but none work for me.</p> <p>I am trying to clone from one machine by connecting to the remote server which is in the LAN network.<br> Running this command from another machine cause error.<br> But running the SAME clone command using git://192.168.8.5 ... at the server it's ...
1,030,103
660,810
2025-06-12 05:58:32
22,317,479
954
2014-03-11 05:50:57
325,452
2015-06-08 18:48:24
https://stackoverflow.com/q/21277806
https://stackoverflow.com/a/22317479
<p>First, turn off compression: </p> <pre><code>git config --global core.compression 0 </code></pre> <p>Next, let's do a partial clone to truncate the amount of info coming down: </p> <pre><code>git clone --depth 1 &lt;repo_URI&gt; </code></pre> <p>When that works, go into the new directory and retrieve the rest of...
<p>First, turn off compression: </p> <pre><code>git config --global core.compression 0 </code></pre> <p>Next, let's do a partial clone to truncate the amount of info coming down: </p> <pre><code>git clone --depth 1 &lt;repo_URI&gt; </code></pre> <p>When that works, go into the new directory and retrieve the rest of...
119, 1731, 21628
cygwin, git, msysgit
<h1>fatal: early EOF fatal: index-pack failed</h1> <p>I have googled and found many solutions but none work for me.</p> <p>I am trying to clone from one machine by connecting to the remote server which is in the LAN network.<br> Running this command from another machine cause error.<br> But running the SAME clone comm...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,058
git
# fatal: early EOF fatal: index-pack failed I have googled and found many solutions but none work for me. I am trying to clone from one machine by connecting to the remote server which is in the LAN network. Running this command from another machine cause error. But running the SAME clone command using git://192....
First, turn off compression: ``` git config --global core.compression 0 ``` Next, let's do a partial clone to truncate the amount of info coming down: ``` git clone --depth 1 <repo_URI> ``` When that works, go into the new directory and retrieve the rest of the clone: ``` git fetch --unshallow ``` or, alternately...
2427288
How to get back to the latest commit after checking out a previous commit?
762
2010-03-11 17:42:58
<p>I sometimes check out some previous version of the code to examine or test. I have seen instructions on what to do if I wish to modify previous commits -- but suppose I make no changes. After I've done e.g. <code>git checkout HEAD^</code>, how do I get back to the tip of the branch?.. <code>git log</code> no longe...
570,159
133,234
2021-09-28 10:35:31
2,427,389
944
2010-03-11 17:56:26
90,002
2015-05-29 15:14:20
https://stackoverflow.com/q/2427288
https://stackoverflow.com/a/2427389
<p>If you know the commit you want to return to is the head of some branch, or is tagged, then you can just</p> <pre><code>git checkout branchname </code></pre> <p>You can also use <code>git reflog</code> to see what other commits your HEAD (or any other ref) has pointed to in the past.</p> <hr> <p>Edited to add:</...
<p>If you know the commit you want to return to is the head of some branch, or is tagged, then you can just</p> <pre><code>git checkout branchname </code></pre> <p>You can also use <code>git reflog</code> to see what other commits your HEAD (or any other ref) has pointed to in the past.</p> <hr> <p>Edited to add:</...
119, 456
git, version-control
<h1>How to get back to the latest commit after checking out a previous commit?</h1> <p>I sometimes check out some previous version of the code to examine or test. I have seen instructions on what to do if I wish to modify previous commits -- but suppose I make no changes. After I've done e.g. <code>git checkout HEAD^...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,060
git
# How to get back to the latest commit after checking out a previous commit? I sometimes check out some previous version of the code to examine or test. I have seen instructions on what to do if I wish to modify previous commits -- but suppose I make no changes. After I've done e.g. `git checkout HEAD^`, how do I get ...
If you know the commit you want to return to is the head of some branch, or is tagged, then you can just ``` git checkout branchname ``` You can also use `git reflog` to see what other commits your HEAD (or any other ref) has pointed to in the past. --- Edited to add: In newer versions of Git, if you only ran `git...
20106712
What are the differences between git remote prune, git prune, git fetch --prune, etc
505
2013-11-20 20:49:55
<p>My situation is this... someone working on the same repo has deleted a branch from his local &amp; remote repo...</p> <p>Most people who have asked about this kind of problem on Stack Overflow, or other sites have the issue of branches still showing in their remote tracking branch list <code>git branch -a</code> at...
475,169
446,936
2022-11-30 22:41:26
20,107,184
944
2013-11-20 21:14:58
683,080
2019-01-25 23:36:55
https://stackoverflow.com/q/20106712
https://stackoverflow.com/a/20107184
<p>I don't blame you for getting frustrated about this. The best way to look at is this. There are potentially three versions of every remote branch:</p> <ol> <li>The actual branch on the remote repository<br> (e.g., remote repo at <a href="https://example.com/repo.git" rel="noreferrer">https://example.com/repo.git...
<p>I don't blame you for getting frustrated about this. The best way to look at is this. There are potentially three versions of every remote branch:</p> <ol> <li>The actual branch on the remote repository<br> (e.g., remote repo at <a href="https://example.com/repo.git" rel="noreferrer">https://example.com/repo.git...
119, 31678
git, remote-branch
<h1>What are the differences between git remote prune, git prune, git fetch --prune, etc</h1> <p>My situation is this... someone working on the same repo has deleted a branch from his local &amp; remote repo...</p> <p>Most people who have asked about this kind of problem on Stack Overflow, or other sites have the issu...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,061
git
# What are the differences between git remote prune, git prune, git fetch --prune, etc My situation is this... someone working on the same repo has deleted a branch from his local & remote repo... Most people who have asked about this kind of problem on Stack Overflow, or other sites have the issue of branches still ...
I don't blame you for getting frustrated about this. The best way to look at is this. There are potentially three versions of every remote branch: 1. The actual branch on the remote repository (e.g., remote repo at <https://example.com/repo.git>, `refs/heads/master`) 2. Your snapshot of that branch locally (store...
1251681
Git mergetool generates unwanted .orig files
602
2009-08-09 16:25:26
<p>When I do a merge conflict resolution with Kdiff3 (and other merge tool I tried) I noticed that on resolution a <code>*.orig</code> file is created. Is there a way for it to not create that extra file?</p>
158,600
35,505
2021-03-12 23:15:41
1,251,696
941
2009-08-09 16:34:25
6,309
2017-10-12 15:45:02
https://stackoverflow.com/q/1251681
https://stackoverflow.com/a/1251696
<p>A possible solution from <a href="http://git-scm.com/docs/git-config" rel="noreferrer"><code>git config</code></a>:</p> <pre><code>git config --global mergetool.keepBackup false </code></pre> <blockquote> <p>After performing a merge, the original file with conflict markers can be saved as a file with a <code>.or...
<p>A possible solution from <a href="http://git-scm.com/docs/git-config" rel="noreferrer"><code>git config</code></a>:</p> <pre><code>git config --global mergetool.keepBackup false </code></pre> <blockquote> <p>After performing a merge, the original file with conflict markers can be saved as a file with a <code>.or...
119, 456
git, version-control
<h1>Git mergetool generates unwanted .orig files</h1> <p>When I do a merge conflict resolution with Kdiff3 (and other merge tool I tried) I noticed that on resolution a <code>*.orig</code> file is created. Is there a way for it to not create that extra file?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,062
git
# Git mergetool generates unwanted .orig files When I do a merge conflict resolution with Kdiff3 (and other merge tool I tried) I noticed that on resolution a `*.orig` file is created. Is there a way for it to not create that extra file?
A possible solution from [`git config`](http://git-scm.com/docs/git-config): ``` git config --global mergetool.keepBackup false ``` > After performing a merge, the original file with conflict markers can be saved as a file with a `.orig` extension. > If this variable is set to `false` then this file is not preserve...
11956710
git recover deleted file where no commit was made after the delete
1,073
2012-08-14 16:27:38
<p>I deleted some files. </p> <p>I did NOT commit yet. </p> <p>I want to reset my workspace to recover the files. </p> <p>I did a <code>git checkout .</code>.</p> <p>But the deleted files are still missing.</p> <p>And <code>git status</code> shows:</p> <pre><code># On branch master # Changes to be committed: #...
918,245
793,454
2023-06-21 12:01:37
11,956,744
922
2012-08-14 16:29:32
229,602
2014-03-03 17:55:49
https://stackoverflow.com/q/11956710
https://stackoverflow.com/a/11956744
<p>The output tells you what you need to do. <code>git reset HEAD cc.properties</code> etc. </p> <p>This will unstage the rm operation. After that, running a <code>git status</code> again will tell you that you need to do a <code>git checkout -- cc.properties</code> to get the file back. </p> <p>Update: I have this i...
<p>The output tells you what you need to do. <code>git reset HEAD cc.properties</code> etc. </p> <p>This will unstage the rm operation. After that, running a <code>git status</code> again will tell you that you need to do a <code>git checkout -- cc.properties</code> to get the file back. </p> <p>Update: I have this i...
119
git
<h1>git recover deleted file where no commit was made after the delete</h1> <p>I deleted some files. </p> <p>I did NOT commit yet. </p> <p>I want to reset my workspace to recover the files. </p> <p>I did a <code>git checkout .</code>.</p> <p>But the deleted files are still missing.</p> <p>And <code>git status</...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,067
git
# git recover deleted file where no commit was made after the delete I deleted some files. I did NOT commit yet. I want to reset my workspace to recover the files. I did a `git checkout .`. But the deleted files are still missing. And `git status` shows: ``` # On branch master # Changes to be committed: # (use...
The output tells you what you need to do. `git reset HEAD cc.properties` etc. This will unstage the rm operation. After that, running a `git status` again will tell you that you need to do a `git checkout -- cc.properties` to get the file back. Update: I have this in my config file ``` $ git config alias.unstage res...
15606955
How can I make git show a list of the files that are being tracked?
789
2013-03-25 03:04:06
<p>Using command line git, how can I make git show a list of the files that are being tracked in the repository?</p>
383,029
554,591
2024-04-20 07:44:51
15,606,995
922
2013-03-25 03:09:47
380,757
2024-01-14 03:36:15
https://stackoverflow.com/q/15606955
https://stackoverflow.com/a/15606995
<p>To list all the files currently being tracked under the branch <code>master</code>, use <a href="https://git-scm.com/docs/git-ls-tree" rel="noreferrer"><code>ls-tree</code></a>:</p> <pre><code>git ls-tree -r master --name-only </code></pre> <p>To list all files that have ever existed (i.e. including deleted files):<...
<p>To list all the files currently being tracked under the branch <code>master</code>, use <a href="https://git-scm.com/docs/git-ls-tree" rel="noreferrer"><code>ls-tree</code></a>:</p> <pre><code>git ls-tree -r master --name-only </code></pre> <p>To list all files that have ever existed (i.e. including deleted files):<...
119
git
<h1>How can I make git show a list of the files that are being tracked?</h1> <p>Using command line git, how can I make git show a list of the files that are being tracked in the repository?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,068
git
# How can I make git show a list of the files that are being tracked? Using command line git, how can I make git show a list of the files that are being tracked in the repository?
To list all the files currently being tracked under the branch `master`, use [`ls-tree`](https://git-scm.com/docs/git-ls-tree): ``` git ls-tree -r master --name-only ``` To list all files that have ever existed (i.e. including deleted files): ``` git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/...
17195861
Undo git update-index --assume-unchanged <file>
722
2013-06-19 15:57:09
<p>I have run the following command to ignore watching/tracking a particular directory/file:</p> <pre><code>git update-index --assume-unchanged &lt;file&gt; </code></pre> <p>How can I undo this, so that <code>&lt;file&gt;</code> is watched/tracked again?</p>
284,808
56,449
2024-04-09 01:24:40
17,195,901
917
2013-06-19 15:58:36
56,449
2024-04-09 01:22:50
https://stackoverflow.com/q/17195861
https://stackoverflow.com/a/17195901
<p>To get undo/show dir's/files that are set to assume-unchanged run this:</p> <pre class="lang-bash prettyprint-override"><code>git update-index --no-assume-unchanged &lt;file&gt; </code></pre> <p>To get a list of dir's/files that are <code>assume-unchanged</code> run this in a unix shell:</p> <pre class="lang-bash p...
<p>To get undo/show dir's/files that are set to assume-unchanged run this:</p> <pre class="lang-bash prettyprint-override"><code>git update-index --no-assume-unchanged &lt;file&gt; </code></pre> <p>To get a list of dir's/files that are <code>assume-unchanged</code> run this in a unix shell:</p> <pre class="lang-bash p...
119, 456, 68400
git, git-index, version-control
<h1>Undo git update-index --assume-unchanged <file></h1> <p>I have run the following command to ignore watching/tracking a particular directory/file:</p> <pre><code>git update-index --assume-unchanged &lt;file&gt; </code></pre> <p>How can I undo this, so that <code>&lt;file&gt;</code> is watched/tracked again?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,069
git
# Undo git update-index --assume-unchanged I have run the following command to ignore watching/tracking a particular directory/file: ``` git update-index --assume-unchanged <file> ``` How can I undo this, so that `<file>` is watched/tracked again?
To get undo/show dir's/files that are set to assume-unchanged run this: ``` git update-index --no-assume-unchanged <file> ``` To get a list of dir's/files that are `assume-unchanged` run this in a unix shell: ``` git ls-files -v | grep '^h' ``` or in a PowerShell: ``` git ls-files -v | Select-String -CaseSensitive...
20929336
Git submodule add: "a git directory is found locally" issue
373
2014-01-05 02:32:03
<p>I'm actually trying to learn how to use git, including the <code>git submodule</code> subcommands. I already set up a server on which I can host, push and pull git repositories by using SSH. I created a main git repository "Travail" on this server in which I would like to put all my projects as submodules.</p> <p>I...
126,324
3,156,085
2023-04-07 04:16:08
35,778,105
906
2016-03-03 16:48:07
3,645,851
2021-01-26 05:49:34
https://stackoverflow.com/q/20929336
https://stackoverflow.com/a/35778105
<p>I came to this SO post trying to add a submodule with the same path as a submodule that I recently deleted.</p> <p>This is what ultimately worked for me (<a href="http://blogs.atlassian.com/2013/03/git-submodules-workflows-tips/" rel="noreferrer">this article helped out a lot</a>):</p> <p>If you haven't already run<...
<p>I came to this SO post trying to add a submodule with the same path as a submodule that I recently deleted.</p> <p>This is what ultimately worked for me (<a href="http://blogs.atlassian.com/2013/03/git-submodules-workflows-tips/" rel="noreferrer">this article helped out a lot</a>):</p> <p>If you haven't already run<...
119, 41612
git, git-submodules
<h1>Git submodule add: "a git directory is found locally" issue</h1> <p>I'm actually trying to learn how to use git, including the <code>git submodule</code> subcommands. I already set up a server on which I can host, push and pull git repositories by using SSH. I created a main git repository "Travail" on this server ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,072
git
# Git submodule add: "a git directory is found locally" issue I'm actually trying to learn how to use git, including the `git submodule` subcommands. I already set up a server on which I can host, push and pull git repositories by using SSH. I created a main git repository "Travail" on this server in which I would lik...
I came to this SO post trying to add a submodule with the same path as a submodule that I recently deleted. This is what ultimately worked for me ([this article helped out a lot](http://blogs.atlassian.com/2013/03/git-submodules-workflows-tips/)): If you haven't already run `git rm --cached path_to_submodule` (no t...
8640887
How to "git merge" without creating a merge commit?
615
2011-12-27 03:29:31
<p>Is it possible to do a <code>git merge</code>, but without a commit?</p> <p>"man git merge" says this:</p> <pre><code>With --no-commit perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge result before committing. </code></pre> <p>B...
475,188
104,458
2024-09-03 03:21:11
8,641,053
905
2011-12-27 04:08:23
526,535
2023-03-22 09:09:59
https://stackoverflow.com/q/8640887
https://stackoverflow.com/a/8641053
<p>Note the output while doing the merge - it is saying <code>Fast Forward</code>.</p> <p>In such situations, you want to do:</p> <pre><code>git merge &lt;name-of-branch&gt; --no-commit --no-ff </code></pre> <p><strong>Important</strong>: If you do it this way, then you are not able to do any changes to the files in th...
<p>Note the output while doing the merge - it is saying <code>Fast Forward</code>.</p> <p>In such situations, you want to do:</p> <pre><code>git merge &lt;name-of-branch&gt; --no-commit --no-ff </code></pre> <p><strong>Important</strong>: If you do it this way, then you are not able to do any changes to the files in th...
119, 28897
git, git-merge
<h1>How to "git merge" without creating a merge commit?</h1> <p>Is it possible to do a <code>git merge</code>, but without a commit?</p> <p>"man git merge" says this:</p> <pre><code>With --no-commit perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,073
git
# How to "git merge" without creating a merge commit? Is it possible to do a `git merge`, but without a commit? "man git merge" says this: ``` With --no-commit perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge result before committi...
Note the output while doing the merge - it is saying `Fast Forward`. In such situations, you want to do: ``` git merge <name-of-branch> --no-commit --no-ff ``` **Important**: If you do it this way, then you are not able to do any changes to the files in the staging area e.g. you can't remove/add files or make any ch...
3639115
Reverting to a specific commit based on commit id with Git?
583
2010-09-03 19:49:46
<p>With <code>git log</code>, I get a list of commits that I have made so far. </p> <pre><code>commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1 Author: prosseek Date: Fri Sep 3 14:36:59 2010 -0500 Added and modified the files. commit c14809fafb08b9e96ff2879999ba8c807d10fb07 Author: prosseek Date: Tue Aug 31...
1,304,988
260,127
2024-08-01 13:11:42
3,639,154
904
2010-09-03 19:54:34
330,184
2020-10-31 13:39:51
https://stackoverflow.com/q/3639115
https://stackoverflow.com/a/3639154
<p>Do you want to roll back your repo to that state, or you just want your local repo to look like that?</p> <p>If you <code>reset --hard</code>, it will make your local code and local history be just like it was at that commit. But if you wanted to push this to someone else who has the new history, it would fail:</p> ...
<p>Do you want to roll back your repo to that state, or you just want your local repo to look like that?</p> <p>If you <code>reset --hard</code>, it will make your local code and local history be just like it was at that commit. But if you wanted to push this to someone else who has the new history, it would fail:</p> ...
119
git
<h1>Reverting to a specific commit based on commit id with Git?</h1> <p>With <code>git log</code>, I get a list of commits that I have made so far. </p> <pre><code>commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1 Author: prosseek Date: Fri Sep 3 14:36:59 2010 -0500 Added and modified the files. commit c14809fa...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,074
git
# Reverting to a specific commit based on commit id with Git? With `git log`, I get a list of commits that I have made so far. ``` commit f5c5cac0033439c17ebf905d4391dc0705dbd5f1 Author: prosseek Date: Fri Sep 3 14:36:59 2010 -0500 Added and modified the files. commit c14809fafb08b9e96ff2879999ba8c807d10fb07...
Do you want to roll back your repo to that state, or you just want your local repo to look like that? If you `reset --hard`, it will make your local code and local history be just like it was at that commit. But if you wanted to push this to someone else who has the new history, it would fail: ``` git reset --hard c1...
2041993
How do I rename a Git repository?
639
2010-01-11 13:11:30
<p><code>git mv</code> renames a file or directory in a repository. How do I rename the Git repository itself?</p>
632,521
153,487
2025-06-26 22:22:16
2,042,020
903
2010-01-11 13:15:27
121,332
2023-03-21 12:23:03
https://stackoverflow.com/q/2041993
https://stackoverflow.com/a/2042020
<p>There are various possible interpretations of what is meant by renaming a Git repository: the displayed name, the repository directory, or the remote repository name. Each requires different steps to rename.</p> <h2>Displayed Name</h2> <p>Rename the displayed name (for example, shown by <code>gitweb</code>):</p> <ol...
<p>There are various possible interpretations of what is meant by renaming a Git repository: the displayed name, the repository directory, or the remote repository name. Each requires different steps to rename.</p> <h2>Displayed Name</h2> <p>Rename the displayed name (for example, shown by <code>gitweb</code>):</p> <ol...
119
git
<h1>How do I rename a Git repository?</h1> <p><code>git mv</code> renames a file or directory in a repository. How do I rename the Git repository itself?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,075
git
# How do I rename a Git repository? `git mv` renames a file or directory in a repository. How do I rename the Git repository itself?
There are various possible interpretations of what is meant by renaming a Git repository: the displayed name, the repository directory, or the remote repository name. Each requires different steps to rename. ## Displayed Name Rename the displayed name (for example, shown by `gitweb`): 1. Edit `.git/description` to c...
153724
How to round a number to n decimal places in Java
1,490
2008-09-30 16:01:34
<p>What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.</p> <p>I also would like only significant digits to be ...
2,170,384
12,149
2024-06-28 01:47:21
153,785
895
2008-09-30 16:14:15
17,651
2020-01-09 14:00:29
https://stackoverflow.com/q/153724
https://stackoverflow.com/a/153785
<p>Use <a href="http://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html#setRoundingMode(java.math.RoundingMode)" rel="noreferrer"><code>setRoundingMode</code></a>, set the <a href="http://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html" rel="noreferrer"><code>RoundingMode</code></a> explicit...
<p>Use <a href="http://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html#setRoundingMode(java.math.RoundingMode)" rel="noreferrer"><code>setRoundingMode</code></a>, set the <a href="http://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html" rel="noreferrer"><code>RoundingMode</code></a> explicit...
17, 6250, 9069, 9914
decimal, digits, java, rounding
<h1>How to round a number to n decimal places in Java</h1> <p>What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situation...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,077
git
# How to round a number to n decimal places in Java What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations. I als...
Use [`setRoundingMode`](http://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html#setRoundingMode(java.math.RoundingMode)), set the [`RoundingMode`](http://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html) explicitly to handle your issue with the half-even round, then use the format pattern for...
7927750
Specify an SSH key for git push for a given domain
561
2011-10-28 09:57:04
<p>I have the following use case: I would like to be able to push to <code>git@git.company.com:gitolite-admin</code> using the private key of user <code>gitolite-admin</code>, while I want to push to <code>git@git.company.com:some_repo</code> using 'my own' private key. AFAIK, I can't solve this using <code>~/.ssh/conf...
476,442
16,784
2024-06-05 21:58:02
7,927,828
892
2011-10-28 10:03:32
223,092
2014-07-30 04:17:28
https://stackoverflow.com/q/7927750
https://stackoverflow.com/a/7927828
<p>Even if the user and host are the same, they can still be distinguished in <code>~/.ssh/config</code>. For example, if your configuration looks like this:</p> <pre><code>Host gitolite-as-alice HostName git.company.com User git IdentityFile /home/whoever/.ssh/id_rsa.alice IdentitiesOnly yes Host gitolite-a...
<p>Even if the user and host are the same, they can still be distinguished in <code>~/.ssh/config</code>. For example, if your configuration looks like this:</p> <pre><code>Host gitolite-as-alice HostName git.company.com User git IdentityFile /home/whoever/.ssh/id_rsa.alice IdentitiesOnly yes Host gitolite-a...
119, 386, 39151
git, gitolite, ssh
<h1>Specify an SSH key for git push for a given domain</h1> <p>I have the following use case: I would like to be able to push to <code>git@git.company.com:gitolite-admin</code> using the private key of user <code>gitolite-admin</code>, while I want to push to <code>git@git.company.com:some_repo</code> using 'my own' pr...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,078
git
# Specify an SSH key for git push for a given domain I have the following use case: I would like to be able to push to `git@git.company.com:gitolite-admin` using the private key of user `gitolite-admin`, while I want to push to `git@git.company.com:some_repo` using 'my own' private key. AFAIK, I can't solve this using...
Even if the user and host are the same, they can still be distinguished in `~/.ssh/config`. For example, if your configuration looks like this: ``` Host gitolite-as-alice HostName git.company.com User git IdentityFile /home/whoever/.ssh/id_rsa.alice IdentitiesOnly yes Host gitolite-as-bob HostName git.compa...
3637660
How to exclude file only from root folder in Git
625
2010-09-03 16:22:20
<p>I am aware of using <code>.gitignore</code> file to exclude some files being added, but I have several <code>config.php</code> files in source tree and I need to exclude only one, located in the root while other keep under revision control. </p> <p>What I should write into <code>.gitignore</code> to make this happe...
187,243
345,364
2021-12-12 14:05:22
3,637,678
881
2010-09-03 16:26:26
140,185
2010-09-03 16:26:26
https://stackoverflow.com/q/3637660
https://stackoverflow.com/a/3637678
<p>From the <a href="http://git-scm.com/docs/gitignore" rel="noreferrer">documentation</a>:</p> <blockquote> <p>If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the wo...
<p>From the <a href="http://git-scm.com/docs/gitignore" rel="noreferrer">documentation</a>:</p> <blockquote> <p>If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the wo...
119, 25056
git, gitignore
<h1>How to exclude file only from root folder in Git</h1> <p>I am aware of using <code>.gitignore</code> file to exclude some files being added, but I have several <code>config.php</code> files in source tree and I need to exclude only one, located in the root while other keep under revision control. </p> <p>What I sh...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,080
git
# How to exclude file only from root folder in Git I am aware of using `.gitignore` file to exclude some files being added, but I have several `config.php` files in source tree and I need to exclude only one, located in the root while other keep under revision control. What I should write into `.gitignore` to make th...
From the [documentation](http://git-scm.com/docs/gitignore): > If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file). > > A le...
4479225
How to output git log with the first line only?
580
2010-12-18 17:39:26
<p>I am trying to customize the format for <code>git log</code>. I want all commits to be shown in one line. Each line should only show the first line of the commit message.<br> I <a href="http://book.git-scm.com/3_reviewing_history_-_git_log.html" rel="noreferrer">found out</a> that <code>git log --pretty=short</code>...
395,190
356,895
2023-09-15 08:45:29
4,488,858
879
2010-12-20 10:43:38
108,802
2021-06-24 17:54:37
https://stackoverflow.com/q/4479225
https://stackoverflow.com/a/4488858
<p>Have you tried this?</p> <pre><code>git log --oneline </code></pre> <p>It's an alias for <code>git log --pretty=oneline --abbrev-commit</code>, and displays the &quot;short sha&quot; and &quot;short description&quot;, for example:</p> <pre><code>9bee8857 Write more code 831fdd6e Write some code Second line of messa...
<p>Have you tried this?</p> <pre><code>git log --oneline </code></pre> <p>It's an alias for <code>git log --pretty=oneline --abbrev-commit</code>, and displays the &quot;short sha&quot; and &quot;short description&quot;, for example:</p> <pre><code>9bee8857 Write more code 831fdd6e Write some code Second line of messa...
119, 456, 555, 942, 3809
commit-message, formatting, git, logging, version-control
<h1>How to output git log with the first line only?</h1> <p>I am trying to customize the format for <code>git log</code>. I want all commits to be shown in one line. Each line should only show the first line of the commit message.<br> I <a href="http://book.git-scm.com/3_reviewing_history_-_git_log.html" rel="noreferre...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,081
git
# How to output git log with the first line only? I am trying to customize the format for `git log`. I want all commits to be shown in one line. Each line should only show the first line of the commit message. I [found out](http://book.git-scm.com/3_reviewing_history_-_git_log.html) that `git log --pretty=short` sho...
Have you tried this? ``` git log --oneline ``` It's an alias for `git log --pretty=oneline --abbrev-commit`, and displays the "short sha" and "short description", for example: ``` 9bee8857 Write more code 831fdd6e Write some code Second line of message ``` The problem is that you are missing an empty line after the...
7901864
Git conflict markers
557
2011-10-26 11:16:57
<p>After I pulled from remote branch, I got conflict, when I open the file it looks something like below:</p> <pre><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD:file.txt Hello world ======= Goodbye &gt;&gt;&gt;&gt;&gt;&gt;&gt; 77976da35a11db4580b80ae27e8d65caf5208086:file.txt </code></pre> <p>I need some explanations of th...
303,908
475,850
2019-02-20 07:11:38
7,901,901
878
2011-10-26 11:20:50
223,092
2019-02-20 07:11:38
https://stackoverflow.com/q/7901864
https://stackoverflow.com/a/7901901
<p>The line (or lines) between the lines beginning <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> and <code>======</code> here:</p> <pre><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD:file.txt Hello world ======= </code></pre> <p>... is what you already had locally - you can tell because <code>HEAD</code> points to your current ...
<p>The line (or lines) between the lines beginning <code>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> and <code>======</code> here:</p> <pre><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD:file.txt Hello world ======= </code></pre> <p>... is what you already had locally - you can tell because <code>HEAD</code> points to your current ...
119, 106113
git, git-merge-conflict
<h1>Git conflict markers</h1> <p>After I pulled from remote branch, I got conflict, when I open the file it looks something like below:</p> <pre><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD:file.txt Hello world ======= Goodbye &gt;&gt;&gt;&gt;&gt;&gt;&gt; 77976da35a11db4580b80ae27e8d65caf5208086:file.txt </code></pre> <p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,082
git
# Git conflict markers After I pulled from remote branch, I got conflict, when I open the file it looks something like below: ``` <<<<<<< HEAD:file.txt Hello world ======= Goodbye >>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt ``` I need some explanations of the markers, which portion of code is pulled fr...
The line (or lines) between the lines beginning `<<<<<<<` and `======` here: ``` <<<<<<< HEAD:file.txt Hello world ======= ``` ... is what you already had locally - you can tell because `HEAD` points to your current branch or commit. The line (or lines) between the lines beginning `=======` and `>>>>>>>`: ``` ======...
170961
What's the strategy for handling CRLF (carriage return, line feed) with Git?
703
2008-10-04 20:39:28
<p>I tried committing files with CRLF-ending lines, but it failed.</p> <p>I spent a whole work day on my Windows computer trying different strategies and was almost drawn to stop trying to use Git and instead try <a href="http://en.wikipedia.org/wiki/Mercurial" rel="noreferrer">Mercurial</a>.</p> <p>How to properly han...
274,439
25,167
2022-10-25 12:52:41
10,855,862
873
2012-06-01 18:56:35
25,167
2016-06-07 14:04:37
https://stackoverflow.com/q/170961
https://stackoverflow.com/a/10855862
<p>Almost four years after asking this question, I have finally found <strong>an answer that completely satisfies me</strong>!</p> <p>See the details in <strong>github:help</strong>'s guide to <a href="https://help.github.com/articles/dealing-with-line-endings/">Dealing with line endings</a>.</p> <blockquote> <p>Gi...
<p>Almost four years after asking this question, I have finally found <strong>an answer that completely satisfies me</strong>!</p> <p>See the details in <strong>github:help</strong>'s guide to <a href="https://help.github.com/articles/dealing-with-line-endings/">Dealing with line endings</a>.</p> <blockquote> <p>Gi...
119, 3285, 3705, 14899, 47852
carriage-return, cross-platform, git, linefeed, newline
<h1>What's the strategy for handling CRLF (carriage return, line feed) with Git?</h1> <p>I tried committing files with CRLF-ending lines, but it failed.</p> <p>I spent a whole work day on my Windows computer trying different strategies and was almost drawn to stop trying to use Git and instead try <a href="http://en.wi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,083
git
# What's the strategy for handling CRLF (carriage return, line feed) with Git? I tried committing files with CRLF-ending lines, but it failed. I spent a whole work day on my Windows computer trying different strategies and was almost drawn to stop trying to use Git and instead try [Mercurial](http://en.wikipedia.org/...
Almost four years after asking this question, I have finally found **an answer that completely satisfies me**! See the details in **github:help**'s guide to [Dealing with line endings](https://help.github.com/articles/dealing-with-line-endings/). > Git allows you to set the line ending properties for a > repo directl...
8223103
Merge up to a specific commit
553
2011-11-22 06:58:24
<p>I created a new branch named <code>newbranch</code> from the <code>master</code> branch in git. Now I have done some work and want to merge <code>newbranch</code> to <code>master</code>; however, I have made some extra changes to <code>newbranch</code> and I want to merge <code>newbranch</code> up to the fourth-from...
277,731
575,284
2022-08-11 12:08:38
8,223,166
870
2011-11-22 07:03:51
357,743
2013-04-23 07:21:28
https://stackoverflow.com/q/8223103
https://stackoverflow.com/a/8223166
<p>Sure, being in <code>master</code> branch all you need to do is:</p> <pre><code>git merge &lt;commit-id&gt; </code></pre> <p>where <code>commit-id</code> is hash of the last commit from <code>newbranch</code> that you want to get in your <code>master</code> branch.</p> <p>You can find out more about any git comma...
<p>Sure, being in <code>master</code> branch all you need to do is:</p> <pre><code>git merge &lt;commit-id&gt; </code></pre> <p>where <code>commit-id</code> is hash of the last commit from <code>newbranch</code> that you want to get in your <code>master</code> branch.</p> <p>You can find out more about any git comma...
119, 28897, 78810
git, git-cherry-pick, git-merge
<h1>Merge up to a specific commit</h1> <p>I created a new branch named <code>newbranch</code> from the <code>master</code> branch in git. Now I have done some work and want to merge <code>newbranch</code> to <code>master</code>; however, I have made some extra changes to <code>newbranch</code> and I want to merge <code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,085
git
# Merge up to a specific commit I created a new branch named `newbranch` from the `master` branch in git. Now I have done some work and want to merge `newbranch` to `master`; however, I have made some extra changes to `newbranch` and I want to merge `newbranch` up to the fourth-from-the-last commit to `master`. I use...
Sure, being in `master` branch all you need to do is: ``` git merge <commit-id> ``` where `commit-id` is hash of the last commit from `newbranch` that you want to get in your `master` branch. You can find out more about any git command by doing `git help <command>`. It that case it's `git help merge`. And docs are s...
9008309
How do I set GIT_SSL_NO_VERIFY for specific repos only?
457
2012-01-25 18:40:59
<p>I have to use a git server without proper certificates, but I don't want to have to do</p> <pre><code>env GIT_SSL_NO_VERIFY=true git command </code></pre> <p>every single time I do a git operation. But I would also like to leave SSL enabled for other git repositories. Is there a way to make this local to a single ...
1,398,655
129,171
2024-04-04 13:37:34
9,008,394
868
2012-01-25 18:46:48
477,878
2022-05-13 13:22:32
https://stackoverflow.com/q/9008309
https://stackoverflow.com/a/9008394
<p>You can do</p> <pre><code>git config http.sslVerify &quot;false&quot; </code></pre> <p>in your specific repo to disable SSL certificate checking for that repo only.</p> <p>This won't work with git <em>clone</em>, since you don't yet have the local git repo to be able to set the flag in yet. Therefore in that case:<...
<p>You can do</p> <pre><code>git config http.sslVerify &quot;false&quot; </code></pre> <p>in your specific repo to disable SSL certificate checking for that repo only.</p> <p>This won't work with git <em>clone</em>, since you don't yet have the local git repo to be able to set the flag in yet. Therefore in that case:<...
119, 641
git, ssl
<h1>How do I set GIT_SSL_NO_VERIFY for specific repos only?</h1> <p>I have to use a git server without proper certificates, but I don't want to have to do</p> <pre><code>env GIT_SSL_NO_VERIFY=true git command </code></pre> <p>every single time I do a git operation. But I would also like to leave SSL enabled for other...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,086
git
# How do I set GIT_SSL_NO_VERIFY for specific repos only? I have to use a git server without proper certificates, but I don't want to have to do ``` env GIT_SSL_NO_VERIFY=true git command ``` every single time I do a git operation. But I would also like to leave SSL enabled for other git repositories. Is there a way...
You can do ``` git config http.sslVerify "false" ``` in your specific repo to disable SSL certificate checking for that repo only. This won't work with git *clone*, since you don't yet have the local git repo to be able to set the flag in yet. Therefore in that case: ``` git -c http.sslVerify=false clone <path> cd ...
1417957
Show just the current branch in Git
507
2009-09-13 15:10:32
<p>Is there a Git command equivalent to:</p> <pre><code>git branch | awk '/\*/ { print $2; }' </code></pre>
241,940
113,019
2025-03-31 14:36:23
1,418,022
866
2009-09-13 15:39:25
135,724
2009-09-13 23:48:42
https://stackoverflow.com/q/1417957
https://stackoverflow.com/a/1418022
<pre><code>$ git rev-parse --abbrev-ref HEAD master </code></pre> <p>This should work with Git 1.6.3 or newer.</p>
<pre><code>$ git rev-parse --abbrev-ref HEAD master </code></pre> <p>This should work with Git 1.6.3 or newer.</p>
119, 1879, 76220
branch, git, git-branch
<h1>Show just the current branch in Git</h1> <p>Is there a Git command equivalent to:</p> <pre><code>git branch | awk '/\*/ { print $2; }' </code></pre>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,087
git
# Show just the current branch in Git Is there a Git command equivalent to: ``` git branch | awk '/\*/ { print $2; }' ```
``` $ git rev-parse --abbrev-ref HEAD master ``` This should work with Git 1.6.3 or newer.
14031970
Git - push current branch shortcut
466
2012-12-25 15:38:39
<p>Is there a shortcut to tell Git to push the current tracking branch to origin? <br/><strong>Note:</strong> I know that I can change the <a href="https://stackoverflow.com/a/948397/138585">default push behavior</a>, but I am looking for an ad-hoc solution that does not change the default behavior.</p> <p>For example,...
194,727
138,585
2021-04-05 10:03:40
20,922,141
866
2014-01-04 14:22:39
213,871
2017-03-28 16:00:32
https://stackoverflow.com/q/14031970
https://stackoverflow.com/a/20922141
<p>According to <a href="https://git-scm.com/docs/git-push#git-push-codegitpushoriginHEADcode" rel="noreferrer"><code>git push</code></a> documentation:</p> <pre><code>git push origin HEAD A handy way to push the current branch to the same name on the remote. </code></pre> <p>So I think what you need is <code>git...
<p>According to <a href="https://git-scm.com/docs/git-push#git-push-codegitpushoriginHEADcode" rel="noreferrer"><code>git push</code></a> documentation:</p> <pre><code>git push origin HEAD A handy way to push the current branch to the same name on the remote. </code></pre> <p>So I think what you need is <code>git...
119
git
<h1>Git - push current branch shortcut</h1> <p>Is there a shortcut to tell Git to push the current tracking branch to origin? <br/><strong>Note:</strong> I know that I can change the <a href="https://stackoverflow.com/a/948397/138585">default push behavior</a>, but I am looking for an ad-hoc solution that does not chan...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,088
git
# Git - push current branch shortcut Is there a shortcut to tell Git to push the current tracking branch to origin? **Note:** I know that I can change the [default push behavior](https://stackoverflow.com/a/948397/138585), but I am looking for an ad-hoc solution that does not change the default behavior. For examp...
According to [`git push`](https://git-scm.com/docs/git-push#git-push-codegitpushoriginHEADcode) documentation: ``` git push origin HEAD A handy way to push the current branch to the same name on the remote. ``` So I think what you need is `git push origin HEAD`. Also it can be useful `git push -u origin HEAD` to ...
12144633
Explain which gitignore rule is ignoring my file
432
2012-08-27 15:07:07
<p>Is there any way to see why some file is getting ignored by git (i.e. which rule in a <code>.gitignore</code> file is causing the file to be ignored)?</p> <p>Imagine I have this (or a much more complex scenario, with hundreds of folders and tens of <code>.gitignore</code> files:</p> <pre><code>/ -.gitignore -folde...
70,499
592,540
2025-10-16 14:33:39
12,168,102
864
2012-08-28 21:58:17
179,332
2025-10-16 14:33:39
https://stackoverflow.com/q/12144633
https://stackoverflow.com/a/12168102
<p>You can use</p> <pre><code>git check-ignore -v filename </code></pre> <p>See <a href="https://git-scm.com/docs/git-check-ignore" rel="noreferrer">the man page</a> for more details.</p> <hr /> <p>A condensed version of <a href="https://stackoverflow.com/posts/12168102/revisions">the full history of this answer</a> fo...
<p>You can use</p> <pre><code>git check-ignore -v filename </code></pre> <p>See <a href="https://git-scm.com/docs/git-check-ignore" rel="noreferrer">the man page</a> for more details.</p> <hr /> <p>A condensed version of <a href="https://stackoverflow.com/posts/12168102/revisions">the full history of this answer</a> fo...
119, 25056
git, gitignore
<h1>Explain which gitignore rule is ignoring my file</h1> <p>Is there any way to see why some file is getting ignored by git (i.e. which rule in a <code>.gitignore</code> file is causing the file to be ignored)?</p> <p>Imagine I have this (or a much more complex scenario, with hundreds of folders and tens of <code>.gi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,089
git
# Explain which gitignore rule is ignoring my file Is there any way to see why some file is getting ignored by git (i.e. which rule in a `.gitignore` file is causing the file to be ignored)? Imagine I have this (or a much more complex scenario, with hundreds of folders and tens of `.gitignore` files: ``` / -.gitigno...
You can use ``` git check-ignore -v filename ``` See [the man page](https://git-scm.com/docs/git-check-ignore) for more details. --- A condensed version of [the full history of this answer](https://stackoverflow.com/posts/12168102/revisions) follows: Originally Git did not provide anything like this. But after see...
5377960
Git: What's the best practice to "git clone" into an existing folder?
755
2011-03-21 13:04:52
<p>I have a working copy of the project, without any source control meta data. Now, I'd like to do the equivalent of git-clone into this folder, and keep my local changes.</p> <p>git-clone doesn't allow me to clone into an existing folder. What is the best practice here?</p>
692,033
11,236
2021-07-19 02:22:24
13,852,329
861
2012-12-13 03:11:45
260,839
2013-01-03 21:44:11
https://stackoverflow.com/q/5377960
https://stackoverflow.com/a/13852329
<p>This can be done by cloning to a new directory, then moving the <code>.git</code> directory into your existing directory.</p> <p>If your existing directory is named "code".</p> <pre><code>git clone https://myrepo.com/git.git temp mv temp/.git code/.git rm -rf temp </code></pre> <p>This can also be done without do...
<p>This can be done by cloning to a new directory, then moving the <code>.git</code> directory into your existing directory.</p> <p>If your existing directory is named "code".</p> <pre><code>git clone https://myrepo.com/git.git temp mv temp/.git code/.git rm -rf temp </code></pre> <p>This can also be done without do...
119
git
<h1>Git: What's the best practice to "git clone" into an existing folder?</h1> <p>I have a working copy of the project, without any source control meta data. Now, I'd like to do the equivalent of git-clone into this folder, and keep my local changes.</p> <p>git-clone doesn't allow me to clone into an existing folder. ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,090
git
# Git: What's the best practice to "git clone" into an existing folder? I have a working copy of the project, without any source control meta data. Now, I'd like to do the equivalent of git-clone into this folder, and keep my local changes. git-clone doesn't allow me to clone into an existing folder. What is the best...
This can be done by cloning to a new directory, then moving the `.git` directory into your existing directory. If your existing directory is named "code". ``` git clone https://myrepo.com/git.git temp mv temp/.git code/.git rm -rf temp ``` This can also be done without doing a checkout during the clone command; more...
13541615
How to remove files that are listed in the .gitignore but still on the repository?
748
2012-11-24 13:22:40
<p>I have some files in my repository that should be ignored, i added them to the .gitignore but, of course, they are not removed from my repository.</p> <p>So my question is, is there a magic command or script using filter-branch that can rewrite my history and remove all these files easily? Or simply a command that ...
427,732
624,551
2025-11-10 15:05:27
13,541,721
855
2012-11-24 13:34:35
604,041
2025-06-19 06:37:15
https://stackoverflow.com/q/13541615
https://stackoverflow.com/a/13541721
<p>You can remove them from the repository manually:</p> <pre><code>git rm --cached file1 file2 dir/file3 </code></pre> <p>Or, if you have a lot of files (-z/-0 ensures all file names are handled):</p> <pre><code>git ls-files -i -c --exclude-standard -z |xargs -0 --no-run-if-empty git rm --cached -- </code></pre> <p>If...
<p>You can remove them from the repository manually:</p> <pre><code>git rm --cached file1 file2 dir/file3 </code></pre> <p>Or, if you have a lot of files (-z/-0 ensures all file names are handled):</p> <pre><code>git ls-files -i -c --exclude-standard -z |xargs -0 --no-run-if-empty git rm --cached -- </code></pre> <p>If...
119, 4333, 25056
git, gitignore, ignore
<h1>How to remove files that are listed in the .gitignore but still on the repository?</h1> <p>I have some files in my repository that should be ignored, i added them to the .gitignore but, of course, they are not removed from my repository.</p> <p>So my question is, is there a magic command or script using filter-bra...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,091
git
# How to remove files that are listed in the .gitignore but still on the repository? I have some files in my repository that should be ignored, i added them to the .gitignore but, of course, they are not removed from my repository. So my question is, is there a magic command or script using filter-branch that can rew...
You can remove them from the repository manually: ``` git rm --cached file1 file2 dir/file3 ``` Or, if you have a lot of files (-z/-0 ensures all file names are handled): ``` git ls-files -i -c --exclude-standard -z |xargs -0 --no-run-if-empty git rm --cached -- ``` If you are using PowerShell on Windows this works...
2517190
How do I force Git to use LF instead of CR+LF under Windows?
683
2010-03-25 16:07:33
<p>I want to force Git to check out files under Windows using just <code>LF</code> not <code>CR+LF</code>.<br /> I checked the two configuration options, but was not able to find the right combination of settings.</p> <p>I want to convert all files to have <code>LF</code> line breaks and keep the <code>LF</code> in the...
513,223
99,834
2025-12-19 10:01:40
13,154,031
854
2012-10-31 08:38:57
758,345
2025-12-19 10:01:40
https://stackoverflow.com/q/2517190
https://stackoverflow.com/a/13154031
<p>The proper way to get LF endings in Windows is to first set <code>core.autocrlf</code> to <code>false</code>:</p> <pre><code>git config --global core.autocrlf false </code></pre> <p>You need to do this if you are using msysgit, because it sets it to <code>true</code> in its system settings.</p> <p>Now git won’t do a...
<p>The proper way to get LF endings in Windows is to first set <code>core.autocrlf</code> to <code>false</code>:</p> <pre><code>git config --global core.autocrlf false </code></pre> <p>You need to do this if you are using msysgit, because it sets it to <code>true</code> in its system settings.</p> <p>Now git won’t do a...
119, 3705, 14899, 47852, 123373
carriage-return, git, git-for-windows, linefeed, newline
<h1>How do I force Git to use LF instead of CR+LF under Windows?</h1> <p>I want to force Git to check out files under Windows using just <code>LF</code> not <code>CR+LF</code>.<br /> I checked the two configuration options, but was not able to find the right combination of settings.</p> <p>I want to convert all files t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,092
git
# How do I force Git to use LF instead of CR+LF under Windows? I want to force Git to check out files under Windows using just `LF` not `CR+LF`. I checked the two configuration options, but was not able to find the right combination of settings. I want to convert all files to have `LF` line breaks and keep the `LF`...
The proper way to get LF endings in Windows is to first set `core.autocrlf` to `false`: ``` git config --global core.autocrlf false ``` You need to do this if you are using msysgit, because it sets it to `true` in its system settings. Now git won’t do any line ending normalization. If you want files you check in to ...
1072171
How do you remove an invalid remote branch reference from Git?
854
2009-07-02 02:39:41
<p>In my current repo I have the following output:</p> <pre><code>$ git branch -a * master remotes/origin/master remotes/public/master </code></pre> <p>I want to delete <code>remotes/public/master</code> from the branch list:</p> <pre><code>$ git branch -d remotes/public/master error: branch 'remotes/public/mast...
354,499
64,313
2024-10-01 07:38:35
1,072,178
851
2009-07-02 02:42:05
15,614
2020-04-19 18:02:29
https://stackoverflow.com/q/1072171
https://stackoverflow.com/a/1072178
<p>You might be needing a cleanup:</p> <pre><code>git gc --prune=now </code></pre> <p>or you might be needing a prune:</p> <pre><code>git remote prune public </code></pre> <blockquote> <p><strong>prune</strong></p> <p>Deletes all stale tracking branches under &lt;name>. These stale branches have already been...
<p>You might be needing a cleanup:</p> <pre><code>git gc --prune=now </code></pre> <p>or you might be needing a prune:</p> <pre><code>git remote prune public </code></pre> <blockquote> <p><strong>prune</strong></p> <p>Deletes all stale tracking branches under &lt;name>. These stale branches have already been...
119, 1879, 31678
branch, git, remote-branch
<h1>How do you remove an invalid remote branch reference from Git?</h1> <p>In my current repo I have the following output:</p> <pre><code>$ git branch -a * master remotes/origin/master remotes/public/master </code></pre> <p>I want to delete <code>remotes/public/master</code> from the branch list:</p> <pre><code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,094
git
# How do you remove an invalid remote branch reference from Git? In my current repo I have the following output: ``` $ git branch -a * master remotes/origin/master remotes/public/master ``` I want to delete `remotes/public/master` from the branch list: ``` $ git branch -d remotes/public/master error: branch 're...
You might be needing a cleanup: ``` git gc --prune=now ``` or you might be needing a prune: ``` git remote prune public ``` > **prune** > > Deletes all stale tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally availabl...
3959924
What's the difference between git clone --mirror and git clone --bare
733
2010-10-18 13:59:38
<p>The git clone help page has this to say about <code>--mirror</code>:</p> <blockquote> <p>Set up a mirror of the remote repository. This implies <code>--bare</code>.</p> </blockquote> <p>But doesn't go into detail about how the <code>--mirror</code> clone is different from a <code>--bare</code> clone.</p>
581,118
121,828
2024-10-10 09:52:41
3,960,063
846
2010-10-18 14:14:50
119,963
2024-09-27 14:43:31
https://stackoverflow.com/q/3959924
https://stackoverflow.com/a/3960063
<p>The difference is that when using <code>--mirror</code>, <em>all</em> refs are copied <em>as-is</em>. This means everything: remote-tracking branches, notes, refs/originals/* (backups from filter-branch). The cloned repo has it all. It's also set up so that a remote update will re-fetch everything from the origin (o...
<p>The difference is that when using <code>--mirror</code>, <em>all</em> refs are copied <em>as-is</em>. This means everything: remote-tracking branches, notes, refs/originals/* (backups from filter-branch). The cloned repo has it all. It's also set up so that a remote update will re-fetch everything from the origin (o...
119, 34099
git, git-clone
<h1>What's the difference between git clone --mirror and git clone --bare</h1> <p>The git clone help page has this to say about <code>--mirror</code>:</p> <blockquote> <p>Set up a mirror of the remote repository. This implies <code>--bare</code>.</p> </blockquote> <p>But doesn't go into detail about how the <code>-...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,096
git
# What's the difference between git clone --mirror and git clone --bare The git clone help page has this to say about `--mirror`: > Set up a mirror of the remote repository. This implies `--bare`. But doesn't go into detail about how the `--mirror` clone is different from a `--bare` clone.
The difference is that when using `--mirror`, *all* refs are copied *as-is*. This means everything: remote-tracking branches, notes, refs/originals/* (backups from filter-branch). The cloned repo has it all. It's also set up so that a remote update will re-fetch everything from the origin (overwriting the copied refs)....
8006393
Force add despite the .gitignore file
637
2011-11-04 08:06:23
<p>Is there a way to force <code>git</code> to add a file despite the <code>.gitignore</code> file?</p>
373,494
298,406
2025-01-30 19:38:54
8,006,450
846
2011-11-04 08:12:05
498,634
2015-10-21 15:04:28
https://stackoverflow.com/q/8006393
https://stackoverflow.com/a/8006450
<p>See <a href="https://git-scm.com/docs/git-add" rel="noreferrer"><code>man git-add</code></a>:</p> <pre><code> -f, --force Allow adding otherwise ignored files. </code></pre> <p>So run this</p> <pre><code>git add --force my/ignore/file.foo </code></pre>
<p>See <a href="https://git-scm.com/docs/git-add" rel="noreferrer"><code>man git-add</code></a>:</p> <pre><code> -f, --force Allow adding otherwise ignored files. </code></pre> <p>So run this</p> <pre><code>git add --force my/ignore/file.foo </code></pre>
119, 25056
git, gitignore
<h1>Force add despite the .gitignore file</h1> <p>Is there a way to force <code>git</code> to add a file despite the <code>.gitignore</code> file?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
14,097
git
# Force add despite the .gitignore file Is there a way to force `git` to add a file despite the `.gitignore` file?
See [`man git-add`](https://git-scm.com/docs/git-add): ``` -f, --force Allow adding otherwise ignored files. ``` So run this ``` git add --force my/ignore/file.foo ```