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
5807137
How can I revert uncommitted changes including files and folders?
1,237
2011-04-27 16:06:09
<p>Is there a Git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?</p>
1,042,625
378,170
2022-05-14 22:03:08
5,812,972
1,994
2011-04-28 02:37:48
4,353
2019-11-09 03:18:50
https://stackoverflow.com/q/5807137
https://stackoverflow.com/a/5812972
<p>You can run these two commands:</p> <pre><code># Revert changes to modified files. git reset --hard # Remove all untracked files and directories. # '-f' is force, '-d' is remove directories. git clean -fd </code></pre>
<p>You can run these two commands:</p> <pre><code># Revert changes to modified files. git reset --hard # Remove all untracked files and directories. # '-f' is force, '-d' is remove directories. git clean -fd </code></pre>
119, 34403, 51381, 53850, 68596
git, git-clean, git-commit, git-reset, git-revert
<h1>How can I revert uncommitted changes including files and folders?</h1> <p>Is there a Git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,853
git
# How can I revert uncommitted changes including files and folders? Is there a Git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?
You can run these two commands: ``` # Revert changes to modified files. git reset --hard # Remove all untracked files and directories. # '-f' is force, '-d' is remove directories. git clean -fd ```
7230820
Skip Git commit hooks
1,228
2011-08-29 13:31:59
<p>I'm looking at a Git hook which looks for print statements in Python code. If a print statement is found, it prevents the Git commit.</p> <p>I want to override this hook and I was told that there is a command to do so. I haven't been able to find it. Any thoughts?</p>
870,590
558,699
2023-05-07 03:31:21
7,230,886
1,989
2011-08-29 13:36:30
6,309
2022-04-01 12:33:50
https://stackoverflow.com/q/7230820
https://stackoverflow.com/a/7230886
<p>Maybe (from <a href="https://git-scm.com/docs/git-commit" rel="noreferrer"><code>git commit</code> man page</a>):</p> <pre><code>git commit --no-verify -m &quot;commit message&quot; ^^^^^^^^^^^ -n --no-verify </code></pre> <blockquote> <p>This option bypasses the pre-commit and commit-msg hooks. See als...
<p>Maybe (from <a href="https://git-scm.com/docs/git-commit" rel="noreferrer"><code>git commit</code> man page</a>):</p> <pre><code>git commit --no-verify -m &quot;commit message&quot; ^^^^^^^^^^^ -n --no-verify </code></pre> <blockquote> <p>This option bypasses the pre-commit and commit-msg hooks. See als...
119, 43087, 53850
git, git-commit, githooks
<h1>Skip Git commit hooks</h1> <p>I'm looking at a Git hook which looks for print statements in Python code. If a print statement is found, it prevents the Git commit.</p> <p>I want to override this hook and I was told that there is a command to do so. I haven't been able to find it. Any thoughts?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,854
git
# Skip Git commit hooks I'm looking at a Git hook which looks for print statements in Python code. If a print statement is found, it prevents the Git commit. I want to override this hook and I was told that there is a command to do so. I haven't been able to find it. Any thoughts?
Maybe (from [`git commit` man page](https://git-scm.com/docs/git-commit)): ``` git commit --no-verify -m "commit message" ^^^^^^^^^^^ -n --no-verify ``` > This option bypasses the pre-commit and commit-msg hooks. See also [githooks(5)](http://git-scm.com/docs/githooks). As commented by [Blaise](https://...
5816688
Resetting remote to a certain commit
1,151
2011-04-28 09:46:48
<p>I want to discard all changes done after commit <code>&lt;commit-hash&gt;</code> . So I did:</p> <pre><code>git reset --hard &lt;commit-hash&gt; </code></pre> <p>Now I want to do the same with my remote. How can I do this? I have done some commits (and pushes) after <code>&lt;commit-hash&gt;</code> and I just want...
1,199,976
149,008
2023-11-24 00:42:31
5,816,761
1,984
2011-04-28 09:54:37
223,092
2019-09-11 09:10:23
https://stackoverflow.com/q/5816688
https://stackoverflow.com/a/5816761
<p>Assuming that your branch is called <code>master</code> both here and remotely, and that your remote is called <code>origin</code> you could do:</p> <pre><code> git reset --hard &lt;commit-hash&gt; git push -f origin master </code></pre> <p>However, you should avoid doing this if anyone else is working with your ...
<p>Assuming that your branch is called <code>master</code> both here and remotely, and that your remote is called <code>origin</code> you could do:</p> <pre><code> git reset --hard &lt;commit-hash&gt; git push -f origin master </code></pre> <p>However, you should avoid doing this if anyone else is working with your ...
119
git
<h1>Resetting remote to a certain commit</h1> <p>I want to discard all changes done after commit <code>&lt;commit-hash&gt;</code> . So I did:</p> <pre><code>git reset --hard &lt;commit-hash&gt; </code></pre> <p>Now I want to do the same with my remote. How can I do this? I have done some commits (and pushes) after <c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,855
git
# Resetting remote to a certain commit I want to discard all changes done after commit `<commit-hash>` . So I did: ``` git reset --hard <commit-hash> ``` Now I want to do the same with my remote. How can I do this? I have done some commits (and pushes) after `<commit-hash>` and I just want to discard them all. Is ju...
Assuming that your branch is called `master` both here and remotely, and that your remote is called `origin` you could do: ``` git reset --hard <commit-hash> git push -f origin master ``` However, you should avoid doing this if anyone else is working with your remote repository and has pulled your changes. In that ...
7124914
How to search a Git repository by commit message?
1,293
2011-08-19 16:57:46
<p>I checked some source code into Git with the commit message &quot;Build 0051&quot;.</p> <p>However, I can't seem to find that source code any more - how do I extract this source from the Git repository, using the command line?</p>
698,228
107,409
2024-06-30 17:27:48
7,124,949
1,953
2011-08-19 17:00:59
252,046
2024-06-30 17:27:48
https://stackoverflow.com/q/7124914
https://stackoverflow.com/a/7124949
<p>To search the commit log (across all branches) for the given text:</p> <pre><code>git log --all --grep='Build 0051' </code></pre> <p>To do so while ignoring case in the grep search:</p> <pre><code>git log --all -i --grep='Build 0051' </code></pre> <p>To search the actual content of commits through a repo's history, ...
<p>To search the commit log (across all branches) for the given text:</p> <pre><code>git log --all --grep='Build 0051' </code></pre> <p>To do so while ignoring case in the grep search:</p> <pre><code>git log --all -i --grep='Build 0051' </code></pre> <p>To search the actual content of commits through a repo's history, ...
119, 47913
git, git-log
<h1>How to search a Git repository by commit message?</h1> <p>I checked some source code into Git with the commit message &quot;Build 0051&quot;.</p> <p>However, I can't seem to find that source code any more - how do I extract this source from the Git repository, using the command line?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,856
git
# How to search a Git repository by commit message? I checked some source code into Git with the commit message "Build 0051". However, I can't seem to find that source code any more - how do I extract this source from the Git repository, using the command line?
To search the commit log (across all branches) for the given text: ``` git log --all --grep='Build 0051' ``` To do so while ignoring case in the grep search: ``` git log --all -i --grep='Build 0051' ``` To search the actual content of commits through a repo's history, use: ``` git grep 'Build 0051' $(git rev-list ...
3527856
Show git diff on file in staging area
1,209
2010-08-20 02:52:21
<p>Is there a way I can see the changes that were made to a <code>file</code> after I have done <code>git add file</code>?</p> <p>That is, when I do: </p> <pre><code>git add file git diff file </code></pre> <p>no diff is shown. I guess there's a way to see the differences since the last commit but I don't know what ...
479,384
220,949
2020-05-06 00:28:29
3,527,985
1,929
2010-08-20 03:27:17
28,804
2015-03-30 03:19:20
https://stackoverflow.com/q/3527856
https://stackoverflow.com/a/3527985
<p>You can show changes that have been staged with the <code>--cached</code> flag:</p> <pre><code>$ git diff --cached </code></pre> <p>In more recent versions of git, you can also use the <code>--staged</code> flag (<code>--staged</code> is a synonym for <code>--cached</code>):</p> <pre><code>$ git diff --staged </c...
<p>You can show changes that have been staged with the <code>--cached</code> flag:</p> <pre><code>$ git diff --cached </code></pre> <p>In more recent versions of git, you can also use the <code>--staged</code> flag (<code>--staged</code> is a synonym for <code>--cached</code>):</p> <pre><code>$ git diff --staged </c...
119, 9033, 74978
git, git-diff, git-stage
<h1>Show git diff on file in staging area</h1> <p>Is there a way I can see the changes that were made to a <code>file</code> after I have done <code>git add file</code>?</p> <p>That is, when I do: </p> <pre><code>git add file git diff file </code></pre> <p>no diff is shown. I guess there's a way to see the differenc...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,857
git
# Show git diff on file in staging area Is there a way I can see the changes that were made to a `file` after I have done `git add file`? That is, when I do: ``` git add file git diff file ``` no diff is shown. I guess there's a way to see the differences since the last commit but I don't know what that is.
You can show changes that have been staged with the `--cached` flag: ``` $ git diff --cached ``` In more recent versions of git, you can also use the `--staged` flag (`--staged` is a synonym for `--cached`): ``` $ git diff --staged ```
5828324
Update Git submodule to latest commit on origin
1,189
2011-04-29 05:41:46
<p>I have a project with a Git submodule. It is from an ssh://... URL, and is on commit A. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit, and change to it.</p> <p>Now, my understanding is that <code>git submodule update</code> should do this, but it doesn't. It doesn't do anythi...
1,095,014
101,999
2024-10-25 17:49:16
5,828,396
1,924
2011-04-29 05:50:56
598,698
2021-03-24 06:23:06
https://stackoverflow.com/q/5828324
https://stackoverflow.com/a/5828396
<p>The <a href="http://git-scm.com/docs/git-submodule" rel="noreferrer"><code>git submodule update</code></a> command actually tells Git that you want your submodules to each check out the commit already specified in the index of the superproject. If you want to <em>update</em> your submodules to the latest commit avai...
<p>The <a href="http://git-scm.com/docs/git-submodule" rel="noreferrer"><code>git submodule update</code></a> command actually tells Git that you want your submodules to each check out the commit already specified in the index of the superproject. If you want to <em>update</em> your submodules to the latest commit avai...
119, 28896, 41612
git, git-pull, git-submodules
<h1>Update Git submodule to latest commit on origin</h1> <p>I have a project with a Git submodule. It is from an ssh://... URL, and is on commit A. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit, and change to it.</p> <p>Now, my understanding is that <code>git submodule update</c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,858
git
# Update Git submodule to latest commit on origin I have a project with a Git submodule. It is from an ssh://... URL, and is on commit A. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit, and change to it. Now, my understanding is that `git submodule update` should do this, but it...
The [`git submodule update`](http://git-scm.com/docs/git-submodule) command actually tells Git that you want your submodules to each check out the commit already specified in the index of the superproject. If you want to *update* your submodules to the latest commit available from their remote, you will need to do this...
6839398
Find when a file was deleted in Git
1,726
2011-07-27 04:23:45
<p>I have a Git repository with n commits.</p> <p>I have a file that I need, and that used to be in the repository, and that I suddenly look for and think "Oh! Where'd that file go?"</p> <p>Is there a (series of) Git command(s) that will tell me that "file really_needed.txt was deleted at commit n-13"?</p> <p>In oth...
519,959
74,919
2025-08-13 18:54:03
16,635,324
1,906
2013-05-19 13:48:00
548,637
2024-01-12 14:13:54
https://stackoverflow.com/q/6839398
https://stackoverflow.com/a/16635324
<p>To show the commits that changed a file, even if the file was deleted, run this command:</p> <pre><code>git log --all -- [file path] </code></pre> <p>If you want to see only the last commit, which deleted the file, use <code>-1</code> in addition to the command above:</p> <pre><code>git log --all -1 -- [file path] <...
<p>To show the commits that changed a file, even if the file was deleted, run this command:</p> <pre><code>git log --all -- [file path] </code></pre> <p>If you want to see only the last commit, which deleted the file, use <code>-1</code> in addition to the command above:</p> <pre><code>git log --all -1 -- [file path] <...
119
git
<h1>Find when a file was deleted in Git</h1> <p>I have a Git repository with n commits.</p> <p>I have a file that I need, and that used to be in the repository, and that I suddenly look for and think "Oh! Where'd that file go?"</p> <p>Is there a (series of) Git command(s) that will tell me that "file really_needed.tx...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,859
git
# Find when a file was deleted in Git I have a Git repository with n commits. I have a file that I need, and that used to be in the repository, and that I suddenly look for and think "Oh! Where'd that file go?" Is there a (series of) Git command(s) that will tell me that "file really_needed.txt was deleted at commit...
To show the commits that changed a file, even if the file was deleted, run this command: ``` git log --all -- [file path] ``` If you want to see only the last commit, which deleted the file, use `-1` in addition to the command above: ``` git log --all -1 -- [file path] ``` NOTE: `git log --full-history -- [file pat...
4468361
Search all of Git history for a string
1,223
2010-12-17 06:49:54
<p>I have a code base which I want to push to GitHub as open source. In this Git-controlled source tree, I have certain configuration files which contain passwords. I made sure not to track this file and I also added it to the <code>.gitignore</code> file. However, I want to be absolutely positive that no sensitive inf...
478,234
101,090
2021-11-25 17:46:55
4,472,267
1,906
2010-12-17 15:57:24
20,045
2021-04-19 15:51:23
https://stackoverflow.com/q/4468361
https://stackoverflow.com/a/4472267
<p>Git can search diffs with the -S option (it's called pickaxe <a href="https://git-scm.com/docs/git-log#Documentation/git-log.txt--Sltstringgt" rel="noreferrer">in the docs</a>)</p> <pre><code>git log -S password </code></pre> <p>This will find any commit that added or removed the string <code>password</code>. Here a...
<p>Git can search diffs with the -S option (it's called pickaxe <a href="https://git-scm.com/docs/git-log#Documentation/git-log.txt--Sltstringgt" rel="noreferrer">in the docs</a>)</p> <pre><code>git log -S password </code></pre> <p>This will find any commit that added or removed the string <code>password</code>. Here a...
119
git
<h1>Search all of Git history for a string</h1> <p>I have a code base which I want to push to GitHub as open source. In this Git-controlled source tree, I have certain configuration files which contain passwords. I made sure not to track this file and I also added it to the <code>.gitignore</code> file. However, I want...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,860
git
# Search all of Git history for a string I have a code base which I want to push to GitHub as open source. In this Git-controlled source tree, I have certain configuration files which contain passwords. I made sure not to track this file and I also added it to the `.gitignore` file. However, I want to be absolutely po...
Git can search diffs with the -S option (it's called pickaxe [in the docs](https://git-scm.com/docs/git-log#Documentation/git-log.txt--Sltstringgt)) ``` git log -S password ``` This will find any commit that added or removed the string `password`. Here a few options: - `-p`: will show the diffs. If you provide a fil...
15745045
How do I resolve git saying "Commit your changes or stash them before you can merge"?
1,129
2013-04-01 14:11:34
<p>I made some updates on my local machine, pushed them to a remote repository, and now I'm trying to pull the changes to the server and I get the message;</p> <pre><code>error: Your local changes to the following files would be overwritten by merge: wp-content/w3tc-config/master.php Please, commit your changes or stas...
2,290,267
417,629
2025-09-09 17:24:52
15,745,424
1,903
2013-04-01 14:34:59
877,235
2018-06-26 10:33:28
https://stackoverflow.com/q/15745045
https://stackoverflow.com/a/15745424
<p>You can't merge with local modifications. Git protects you from losing potentially important changes.</p> <p>You have three options: </p> <ul> <li><h2>Commit the change using</h2> <pre><code>git commit -m "My message" </code></pre></li> <li><h2>Stash it.</h2> <p>Stashing acts as a stack, where you can push chang...
<p>You can't merge with local modifications. Git protects you from losing potentially important changes.</p> <p>You have three options: </p> <ul> <li><h2>Commit the change using</h2> <pre><code>git commit -m "My message" </code></pre></li> <li><h2>Stash it.</h2> <p>Stashing acts as a stack, where you can push chang...
119, 53850
git, git-commit
<h1>How do I resolve git saying "Commit your changes or stash them before you can merge"?</h1> <p>I made some updates on my local machine, pushed them to a remote repository, and now I'm trying to pull the changes to the server and I get the message;</p> <pre><code>error: Your local changes to the following files would...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,861
git
# How do I resolve git saying "Commit your changes or stash them before you can merge"? I made some updates on my local machine, pushed them to a remote repository, and now I'm trying to pull the changes to the server and I get the message; ``` error: Your local changes to the following files would be overwritten by ...
You can't merge with local modifications. Git protects you from losing potentially important changes. You have three options: - ## Commit the change using ``` git commit -m "My message" ``` - ## Stash it. Stashing acts as a stack, where you can push changes, and you pop them in reverse order. To stash, t...
22682870
How can I undo pushed commits using Git?
1,653
2014-03-27 09:11:42
<p>I have a project in a remote repository, synchronized with a local repository (development) and the server one (production).</p> <p>I've been making some committed changes already pushed to remote and pulled from the server. Now, I want to undo those changes. So I could just <code>git checkout</code> to the commit b...
2,771,853
2,571,840
2025-04-04 02:06:15
22,683,231
1,900
2014-03-27 09:27:47
1,248,175
2025-01-21 14:31:26
https://stackoverflow.com/q/22682870
https://stackoverflow.com/a/22683231
<p>You can revert individual commits with:</p> <pre class="lang-bash prettyprint-override"><code>git revert &lt;commit_hash&gt; </code></pre> <p>This will create a new commit which reverts the changes of the commit you specified. Note that it only reverts that specific commit, and not commits that come after that. If y...
<p>You can revert individual commits with:</p> <pre class="lang-bash prettyprint-override"><code>git revert &lt;commit_hash&gt; </code></pre> <p>This will create a new commit which reverts the changes of the commit you specified. Note that it only reverts that specific commit, and not commits that come after that. If y...
119, 34403, 51381
git, git-reset, git-revert
<h1>How can I undo pushed commits using Git?</h1> <p>I have a project in a remote repository, synchronized with a local repository (development) and the server one (production).</p> <p>I've been making some committed changes already pushed to remote and pulled from the server. Now, I want to undo those changes. So I co...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,862
git
# How can I undo pushed commits using Git? I have a project in a remote repository, synchronized with a local repository (development) and the server one (production). I've been making some committed changes already pushed to remote and pulled from the server. Now, I want to undo those changes. So I could just `git c...
You can revert individual commits with: ``` git revert <commit_hash> ``` This will create a new commit which reverts the changes of the commit you specified. Note that it only reverts that specific commit, and not commits that come after that. If you want to revert a range of commits, you can do it like this: ``` gi...
3212459
Is there a command to undo git init?
1,032
2010-07-09 12:16:51
<p>I just Git init'ed a repos with a wrong user, and want to undo it. Is there any command for this? Do I actually have to go in and edit the .git directory?</p>
853,261
165,673
2024-08-12 06:04:28
3,212,465
1,882
2010-07-09 12:17:38
47,773
2024-08-09 06:09:43
https://stackoverflow.com/q/3212459
https://stackoverflow.com/a/3212465
<p>If you just inited it, you can just delete .git.</p> <p>Typically:</p> <pre><code>rm -rf .git </code></pre> <p>Then, recreate as the right user.</p> <p>EDIT: <strong>NOTE</strong>: This deletes the entire git repository (including all commit history, etc.). On a newly-created repository, there is no history yet.</p...
<p>If you just inited it, you can just delete .git.</p> <p>Typically:</p> <pre><code>rm -rf .git </code></pre> <p>Then, recreate as the right user.</p> <p>EDIT: <strong>NOTE</strong>: This deletes the entire git repository (including all commit history, etc.). On a newly-created repository, there is no history yet.</p...
119, 106207
git, git-init
<h1>Is there a command to undo git init?</h1> <p>I just Git init'ed a repos with a wrong user, and want to undo it. Is there any command for this? Do I actually have to go in and edit the .git directory?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,863
git
# Is there a command to undo git init? I just Git init'ed a repos with a wrong user, and want to undo it. Is there any command for this? Do I actually have to go in and edit the .git directory?
If you just inited it, you can just delete .git. Typically: ``` rm -rf .git ``` Then, recreate as the right user. EDIT: **NOTE**: This deletes the entire git repository (including all commit history, etc.). On a newly-created repository, there is no history yet.
3338126
How do I diff the same file between two different commits on the same branch?
1,509
2010-07-26 19:10:24
<p>In Git, how could I compare the same file between two different commits (not contiguous) on the same branch (master for example)?</p> <p>I'm searching for a <strong><em>compare</em></strong> feature like the one in <a href="https://en.wikipedia.org/wiki/Microsoft_Visual_SourceSafe" rel="noreferrer">Visual SourceSaf...
1,151,697
130,929
2023-04-20 20:25:46
3,338,145
1,881
2010-07-26 19:13:13
28,804
2016-01-20 05:25:17
https://stackoverflow.com/q/3338126
https://stackoverflow.com/a/3338145
<p>From the <a href="https://www.kernel.org/pub/software/scm/git/docs/git-diff.html" rel="noreferrer" title="Kernel.org version of git-diff manpage"><code>git-diff</code></a> manpage:</p> <pre><code>git diff [--options] &lt;commit&gt; &lt;commit&gt; [--] [&lt;path&gt;...] </code></pre> <p>For instance, to see the dif...
<p>From the <a href="https://www.kernel.org/pub/software/scm/git/docs/git-diff.html" rel="noreferrer" title="Kernel.org version of git-diff manpage"><code>git-diff</code></a> manpage:</p> <pre><code>git diff [--options] &lt;commit&gt; &lt;commit&gt; [--] [&lt;path&gt;...] </code></pre> <p>For instance, to see the dif...
119, 9033
git, git-diff
<h1>How do I diff the same file between two different commits on the same branch?</h1> <p>In Git, how could I compare the same file between two different commits (not contiguous) on the same branch (master for example)?</p> <p>I'm searching for a <strong><em>compare</em></strong> feature like the one in <a href="https...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,864
git
# How do I diff the same file between two different commits on the same branch? In Git, how could I compare the same file between two different commits (not contiguous) on the same branch (master for example)? I'm searching for a ***compare*** feature like the one in [Visual SourceSafe](https://en.wikipedia.org/wiki/...
From the [`git-diff`](https://www.kernel.org/pub/software/scm/git/docs/git-diff.html "Kernel.org version of git-diff manpage") manpage: ``` git diff [--options] <commit> <commit> [--] [<path>...] ``` For instance, to see the difference for a file "main.c" between now and two commits back, here are three equivalent co...
35979642
What is git tag, How to create tags & How to checkout git remote tag(s)
909
2016-03-14 04:38:50
<p>when I checkout remote git tag use command like this:</p> <pre><code>git checkout -b local_branch_name origin/remote_tag_name </code></pre> <p>I got error like this:</p> <blockquote> <p>error: pathspec <code>origin/remote_tag_name</code> did not match any file(s) known to git.</p> </blockquote> <p>I can find remote_...
1,302,713
4,591,230
2023-08-10 19:43:02
35,979,751
1,879
2016-03-14 04:49:44
1,755,598
2023-08-10 19:43:02
https://stackoverflow.com/q/35979642
https://stackoverflow.com/a/35979751
<h3>Let's start by explaining what a tag in git is</h3> <p><a href="https://i.sstatic.net/yRIIc.png" rel="noreferrer"><img src="https://i.sstatic.net/yRIIc.png" alt="enter image description here" /></a></p> <blockquote> <p>A tag is used to label and mark a specific <strong>commit</strong> in the history.<br /> It is us...
<h3>Let's start by explaining what a tag in git is</h3> <p><a href="https://i.sstatic.net/yRIIc.png" rel="noreferrer"><img src="https://i.sstatic.net/yRIIc.png" alt="enter image description here" /></a></p> <blockquote> <p>A tag is used to label and mark a specific <strong>commit</strong> in the history.<br /> It is us...
119, 37230, 60718, 110651
git, git-checkout, git-refspec, git-tag
<h1>What is git tag, How to create tags & How to checkout git remote tag(s)</h1> <p>when I checkout remote git tag use command like this:</p> <pre><code>git checkout -b local_branch_name origin/remote_tag_name </code></pre> <p>I got error like this:</p> <blockquote> <p>error: pathspec <code>origin/remote_tag_name</code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,865
git
# What is git tag, How to create tags & How to checkout git remote tag(s) when I checkout remote git tag use command like this: ``` git checkout -b local_branch_name origin/remote_tag_name ``` I got error like this: > error: pathspec `origin/remote_tag_name` did not match any file(s) known to git. I can find remot...
### Let's start by explaining what a tag in git is [![enter image description here](https://i.sstatic.net/yRIIc.png)](https://i.sstatic.net/yRIIc.png) > A tag is used to label and mark a specific **commit** in the history. > It is usually used to mark release points (eg. v1.0, etc.). > Although a tag may appear si...
783811
Getting Git to work with a proxy server - fails with "Request timed out"
1,044
2009-04-23 22:32:53
<p>How do I get Git to use a proxy server?</p> <p>I need to check out code from a Git server, but it shows "Request timed out" every time. How do I get around this? </p> <p>Alternatively, how can I set a proxy server?</p>
1,437,974
2,288,585
2024-08-18 04:45:00
19,213,999
1,856
2013-10-06 21:10:25
2,678,170
2023-03-18 18:51:26
https://stackoverflow.com/q/783811
https://stackoverflow.com/a/19213999
<p>The command to use:</p> <pre><code>git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 </code></pre> <ul> <li>change <code>proxyuser</code> to your proxy user</li> <li>change <code>proxypwd</code> to your proxy password</li> <li>change <code>proxy.server.com</code> to the URL of your proxy...
<p>The command to use:</p> <pre><code>git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 </code></pre> <ul> <li>change <code>proxyuser</code> to your proxy user</li> <li>change <code>proxypwd</code> to your proxy password</li> <li>change <code>proxy.server.com</code> to the URL of your proxy...
119, 456, 760
git, proxy, version-control
<h1>Getting Git to work with a proxy server - fails with "Request timed out"</h1> <p>How do I get Git to use a proxy server?</p> <p>I need to check out code from a Git server, but it shows "Request timed out" every time. How do I get around this? </p> <p>Alternatively, how can I set a proxy server?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,867
git
# Getting Git to work with a proxy server - fails with "Request timed out" How do I get Git to use a proxy server? I need to check out code from a Git server, but it shows "Request timed out" every time. How do I get around this? Alternatively, how can I set a proxy server?
The command to use: ``` git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 ``` - change `proxyuser` to your proxy user - change `proxypwd` to your proxy password - change `proxy.server.com` to the URL of your proxy server - change `8080` to the proxy port configured on your proxy server N...
948354
Default behavior of "git push" without a branch specified
1,564
2009-06-04 02:45:57
<p>I use the following command to push to my remote branch:</p> <pre><code>git push origin sandbox </code></pre> <p>If I say</p> <pre><code>git push origin </code></pre> <p>does that push changes in my other branches too, or does it only update my current branch? I have three branches: <code>master</code>, <code>pr...
786,616
2,288,585
2022-07-17 19:00:36
948,397
1,824
2009-06-04 03:02:57
25,848
2022-03-21 10:43:29
https://stackoverflow.com/q/948354
https://stackoverflow.com/a/948397
<p>You can control the default behavior by setting push.default in your git config. From <a href="https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault" rel="noreferrer">the git-config(1) documentation</a>:</p> <pre><code>push.default </code></pre> <p>Defines the action git push should take if no...
<p>You can control the default behavior by setting push.default in your git config. From <a href="https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault" rel="noreferrer">the git-config(1) documentation</a>:</p> <pre><code>push.default </code></pre> <p>Defines the action git push should take if no...
119, 1879, 28898, 76220
branch, git, git-branch, git-push
<h1>Default behavior of "git push" without a branch specified</h1> <p>I use the following command to push to my remote branch:</p> <pre><code>git push origin sandbox </code></pre> <p>If I say</p> <pre><code>git push origin </code></pre> <p>does that push changes in my other branches too, or does it only update my c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,869
git
# Default behavior of "git push" without a branch specified I use the following command to push to my remote branch: ``` git push origin sandbox ``` If I say ``` git push origin ``` does that push changes in my other branches too, or does it only update my current branch? I have three branches: `master`, `producti...
You can control the default behavior by setting push.default in your git config. From [the git-config(1) documentation](https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault): ``` push.default ``` Defines the action git push should take if no refspec is given on the command line, no refspec is ...
19003009
How to recover stashed uncommitted changes
1,083
2013-09-25 10:56:21
<p>I had some uncommitted changes in my development branch and I stashed them using <code>git stash</code>, but there were some changes which were very important among those stashed ones. Is there any way to get back those changes?</p> <p>Also, I have made some changes on top of the stashed code files since. </p> <p...
1,395,827
1,237,656
2024-04-18 07:26:29
19,003,191
1,801
2013-09-25 11:03:52
1,256,452
2021-09-01 14:09:04
https://stackoverflow.com/q/19003009
https://stackoverflow.com/a/19003191
<h2>The easy answer to the easy question is <code>git stash apply</code></h2> <p>Just check out the branch you want your changes on, and then <code>git stash apply</code>. Then use <code>git diff</code> to see the result.</p> <p>After you're all done with your changes—the <code>apply</code> looks good and you're sure ...
<h2>The easy answer to the easy question is <code>git stash apply</code></h2> <p>Just check out the branch you want your changes on, and then <code>git stash apply</code>. Then use <code>git diff</code> to see the result.</p> <p>After you're all done with your changes—the <code>apply</code> looks good and you're sure ...
119, 13091
git, git-stash
<h1>How to recover stashed uncommitted changes</h1> <p>I had some uncommitted changes in my development branch and I stashed them using <code>git stash</code>, but there were some changes which were very important among those stashed ones. Is there any way to get back those changes?</p> <p>Also, I have made some chang...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,870
git
# How to recover stashed uncommitted changes I had some uncommitted changes in my development branch and I stashed them using `git stash`, but there were some changes which were very important among those stashed ones. Is there any way to get back those changes? Also, I have made some changes on top of the stashed co...
## The easy answer to the easy question is `git stash apply` Just check out the branch you want your changes on, and then `git stash apply`. Then use `git diff` to see the result. After you're all done with your changes—the `apply` looks good and you're sure you don't need the stash any more—*then* use `git stash dro...
1257592
How do I remove files saying "old mode 100755 new mode 100644" from unstaged changes in Git?
1,043
2009-08-10 22:30:03
<p>For some reason, when I initially did a pull from the repository for a Git project of mine, I got a ton of files in my working copy that don't have any discernible changes made to them, but they keep showing up in my <code>unstaged changes</code> area.</p> <p>I'm using <a href="https://git-scm.com/docs/git-gui" rel=...
391,229
141,822
2025-03-30 23:01:56
1,257,613
1,798
2009-08-10 22:34:45
148,870
2025-03-30 18:45:58
https://stackoverflow.com/q/1257592
https://stackoverflow.com/a/1257613
<p>That looks like Unix file permissions modes to me (<code>755</code>=<code>rwxr-xr-x</code>, <code>644</code>=<code>rw-r--r--</code>). The old mode included the +x (executable) flag, and the new mode doesn't.</p> <p><a href="https://groups.google.com/forum/#!topic/msysgit/hrnEguNBNmw" rel="noreferrer">This MSysGit is...
<p>That looks like Unix file permissions modes to me (<code>755</code>=<code>rwxr-xr-x</code>, <code>644</code>=<code>rw-r--r--</code>). The old mode included the +x (executable) flag, and the new mode doesn't.</p> <p><a href="https://groups.google.com/forum/#!topic/msysgit/hrnEguNBNmw" rel="noreferrer">This MSysGit is...
119, 33729
git, git-gui
<h1>How do I remove files saying "old mode 100755 new mode 100644" from unstaged changes in Git?</h1> <p>For some reason, when I initially did a pull from the repository for a Git project of mine, I got a ton of files in my working copy that don't have any discernible changes made to them, but they keep showing up in m...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,871
git
# How do I remove files saying "old mode 100755 new mode 100644" from unstaged changes in Git? For some reason, when I initially did a pull from the repository for a Git project of mine, I got a ton of files in my working copy that don't have any discernible changes made to them, but they keep showing up in my `unstag...
That looks like Unix file permissions modes to me (`755`=`rwxr-xr-x`, `644`=`rw-r--r--`). The old mode included the +x (executable) flag, and the new mode doesn't. [This MSysGit issue's replies](https://groups.google.com/forum/#!topic/msysgit/hrnEguNBNmw) suggests setting *core.filemode* to false in order to get rid o...
2114111
Where is the global Git configuration data stored?
1,439
2010-01-22 00:34:55
<p>When using <code>git config --global</code> to set things up, which file will it write to?</p> <p>Example:</p> <pre class="lang-none prettyprint-override"><code>git config --global core.editor &quot;blah&quot; </code></pre> <p>I can't find it at these places:</p> <pre class="lang-none prettyprint-override"><code>C:\...
1,255,086
119,790
2025-07-25 13:09:15
2,115,116
1,796
2010-01-22 05:02:38
6,309
2021-01-05 17:09:58
https://stackoverflow.com/q/2114111
https://stackoverflow.com/a/2115116
<p>Update 2016: with git 2.8 (March 2016), you can simply use:</p> <pre><code>git config --list --show-origin </code></pre> <p>And with Git 2.26 (Q1 2020), you can <a href="https://stackoverflow.com/a/60286340/6309">add a <code>--show-scope</code> option</a></p> <pre><code>git config --list --show-origin --show-scope <...
<p>Update 2016: with git 2.8 (March 2016), you can simply use:</p> <pre><code>git config --list --show-origin </code></pre> <p>And with Git 2.26 (Q1 2020), you can <a href="https://stackoverflow.com/a/60286340/6309">add a <code>--show-scope</code> option</a></p> <pre><code>git config --list --show-origin --show-scope <...
119, 3574
config, git
<h1>Where is the global Git configuration data stored?</h1> <p>When using <code>git config --global</code> to set things up, which file will it write to?</p> <p>Example:</p> <pre class="lang-none prettyprint-override"><code>git config --global core.editor &quot;blah&quot; </code></pre> <p>I can't find it at these place...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,872
git
# Where is the global Git configuration data stored? When using `git config --global` to set things up, which file will it write to? Example: ``` git config --global core.editor "blah" ``` I can't find it at these places: ``` C:\Program Files\Git\etc\gitconfig C:\myapp\.git\config ``` I have not set an ENV(?). ...
Update 2016: with git 2.8 (March 2016), you can simply use: ``` git config --list --show-origin ``` And with Git 2.26 (Q1 2020), you can [add a `--show-scope` option](https://stackoverflow.com/a/60286340/6309) ``` git config --list --show-origin --show-scope ``` You will see which config is set where. See "[Where...
11621768
How can I make git accept a self signed certificate?
986
2012-07-23 23:00:06
<p>Using Git, is there a way to tell it to accept a self signed certificate?</p> <p>I am using an https server to host a git server but for now the certificate is self signed.</p> <p>When I try to create the repo there for the first time:</p> <pre><code>git push origin master -f </code></pre> <p>I get the error:</p...
1,830,471
172,861
2024-09-08 20:46:22
11,622,001
1,796
2012-07-23 23:28:17
877,115
2022-06-23 21:47:41
https://stackoverflow.com/q/11621768
https://stackoverflow.com/a/11622001
<h3>To permanently accept a specific certificate</h3> <p>Try <code>http.sslCAPath</code> or <code>http.sslCAInfo</code>. <a href="https://stackoverflow.com/a/26785963/877115">Adam Spiers's answer</a> gives some great examples. This is the most secure solution to the question.</p> <h3>To disable TLS/SSL verification for...
<h3>To permanently accept a specific certificate</h3> <p>Try <code>http.sslCAPath</code> or <code>http.sslCAInfo</code>. <a href="https://stackoverflow.com/a/26785963/877115">Adam Spiers's answer</a> gives some great examples. This is the most secure solution to the question.</p> <h3>To disable TLS/SSL verification for...
119, 456, 642, 12049
git, https, self-signed, version-control
<h1>How can I make git accept a self signed certificate?</h1> <p>Using Git, is there a way to tell it to accept a self signed certificate?</p> <p>I am using an https server to host a git server but for now the certificate is self signed.</p> <p>When I try to create the repo there for the first time:</p> <pre><code>g...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,873
git
# How can I make git accept a self signed certificate? Using Git, is there a way to tell it to accept a self signed certificate? I am using an https server to host a git server but for now the certificate is self signed. When I try to create the repo there for the first time: ``` git push origin master -f ``` I ge...
### To permanently accept a specific certificate Try `http.sslCAPath` or `http.sslCAInfo`. [Adam Spiers's answer](https://stackoverflow.com/a/26785963/877115) gives some great examples. This is the most secure solution to the question. ### To disable TLS/SSL verification for a single git command try passing `-c` to ...
2745076
What are the differences between "git commit" and "git push"?
1,011
2010-04-30 14:17:12
<p>In a Git tutorial I'm going through, <code>git commit</code> is used to store the changes you've made. </p> <p>What is <code>git push</code> used for then?</p>
987,897
173,634
2022-10-18 00:14:14
2,745,097
1,795
2010-04-30 14:20:17
52,444
2022-06-16 18:03:30
https://stackoverflow.com/q/2745076
https://stackoverflow.com/a/2745097
<p>Basically, <code>git commit</code> &quot;<em>records changes to the repository</em>&quot; while <code>git push</code> &quot;<em>updates remote refs along with associated objects</em>&quot;. So the first one is used in connection with your local repository, while the latter one is used to interact with a remote repos...
<p>Basically, <code>git commit</code> &quot;<em>records changes to the repository</em>&quot; while <code>git push</code> &quot;<em>updates remote refs along with associated objects</em>&quot;. So the first one is used in connection with your local repository, while the latter one is used to interact with a remote repos...
119, 4236, 28898, 53850, 68400
git, git-commit, git-index, git-push, push
<h1>What are the differences between "git commit" and "git push"?</h1> <p>In a Git tutorial I'm going through, <code>git commit</code> is used to store the changes you've made. </p> <p>What is <code>git push</code> used for then?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,874
git
# What are the differences between "git commit" and "git push"? In a Git tutorial I'm going through, `git commit` is used to store the changes you've made. What is `git push` used for then?
Basically, `git commit` "*records changes to the repository*" while `git push` "*updates remote refs along with associated objects*". So the first one is used in connection with your local repository, while the latter one is used to interact with a remote repository. Here is a nice picture from [Oliver Steele](http://...
19859486
How to un-commit last un-pushed git commit without losing the changes
1,048
2013-11-08 12:47:23
<p>Is there a way to revert a commit so that my local copy <em>keeps</em> the changes made in that commit, but they become non-committed changes in my working copy? Rolling back a commit takes you to the previous commit - I want to keep the changes made but I committed them to the wrong branch.</p> <p>This has not bee...
714,914
197,229
2025-05-02 17:11:41
19,859,644
1,768
2013-11-08 12:55:01
1,990,682
2020-05-05 18:38:53
https://stackoverflow.com/q/19859486
https://stackoverflow.com/a/19859644
<p>There are a lot of ways to do so, for example:</p> <p>in case you have <strong><em>not</em></strong> pushed the commit publicly yet:</p> <pre><code>git reset HEAD~1 --soft </code></pre> <p>That's it, your commit changes will be in your working directory, whereas the LAST commit will be removed from your curren...
<p>There are a lot of ways to do so, for example:</p> <p>in case you have <strong><em>not</em></strong> pushed the commit publicly yet:</p> <pre><code>git reset HEAD~1 --soft </code></pre> <p>That's it, your commit changes will be in your working directory, whereas the LAST commit will be removed from your curren...
119
git
<h1>How to un-commit last un-pushed git commit without losing the changes</h1> <p>Is there a way to revert a commit so that my local copy <em>keeps</em> the changes made in that commit, but they become non-committed changes in my working copy? Rolling back a commit takes you to the previous commit - I want to keep the ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,875
git
# How to un-commit last un-pushed git commit without losing the changes Is there a way to revert a commit so that my local copy *keeps* the changes made in that commit, but they become non-committed changes in my working copy? Rolling back a commit takes you to the previous commit - I want to keep the changes made but...
There are a lot of ways to do so, for example: in case you have ***not*** pushed the commit publicly yet: ``` git reset HEAD~1 --soft ``` That's it, your commit changes will be in your working directory, whereas the LAST commit will be removed from your current branch. See [git reset man](http://git-scm.com/docs/git...
1419623
How to list branches that contain a given commit?
1,320
2009-09-14 04:03:10
<p>How can I query git to find out which branches contain a given commit? <code>gitk</code> will usually list the branches, unless there are too many, in which case it just says "many (38)" or something like that. I need to know the full list, or at least whether certain branches contain the commit.</p>
403,342
46,926
2024-08-01 08:18:19
1,419,637
1,765
2009-09-14 04:08:58
6,309
2024-08-01 08:18:19
https://stackoverflow.com/q/1419623
https://stackoverflow.com/a/1419637
<p>From the <a href="https://git-scm.com/docs/git-branch#Documentation/git-branch.txt---containsltcommitgt" rel="noreferrer">git-branch manual page</a>:</p> <pre><code> git branch --contains &lt;commit&gt; </code></pre> <blockquote> <p>Only list branches which contain the specified commit (HEAD if not specified). Impli...
<p>From the <a href="https://git-scm.com/docs/git-branch#Documentation/git-branch.txt---containsltcommitgt" rel="noreferrer">git-branch manual page</a>:</p> <pre><code> git branch --contains &lt;commit&gt; </code></pre> <blockquote> <p>Only list branches which contain the specified commit (HEAD if not specified). Impli...
119, 456
git, version-control
<h1>How to list branches that contain a given commit?</h1> <p>How can I query git to find out which branches contain a given commit? <code>gitk</code> will usually list the branches, unless there are too many, in which case it just says "many (38)" or something like that. I need to know the full list, or at least wheth...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,876
git
# How to list branches that contain a given commit? How can I query git to find out which branches contain a given commit? `gitk` will usually list the branches, unless there are too many, in which case it just says "many (38)" or something like that. I need to know the full list, or at least whether certain branches ...
From the [git-branch manual page](https://git-scm.com/docs/git-branch#Documentation/git-branch.txt---containsltcommitgt): ``` git branch --contains <commit> ``` > Only list branches which contain the specified commit (HEAD if not specified). Implies `--list`. > (Use `'-a'` option before `'--contains'` to look in all...
1115854
How to resolve "Error: bad index – Fatal: index file corrupt" when using Git
843
2009-07-12 11:23:10
<p>After <code>git init</code>, I added and committed a few files, made some changes, added and committed. Set up the git daemon (running under Cygwin on WinXP) and cloned the repository once. Now, I get this error with the cloned repository:</p> <pre><code>$ git status error: bad index file sha1 signature fatal: ind...
390,141
107,037
2025-09-09 10:50:20
1,115,956
1,753
2009-07-12 12:28:32
46,058
2021-06-01 17:30:30
https://stackoverflow.com/q/1115854
https://stackoverflow.com/a/1115956
<p>If the problem is with the index as <strong>the staging area for commits</strong> (i.e. <code>.git/index</code>), you can simply remove the index (make a backup copy if you want), and then restore index to version in the last commit:</p> <p>On OSX/Linux/Windows(With Git bash):</p> <pre><code>rm -f .git/index git res...
<p>If the problem is with the index as <strong>the staging area for commits</strong> (i.e. <code>.git/index</code>), you can simply remove the index (make a backup copy if you want), and then restore index to version in the last commit:</p> <p>On OSX/Linux/Windows(With Git bash):</p> <pre><code>rm -f .git/index git res...
119, 10816
corruption, git
<h1>How to resolve "Error: bad index – Fatal: index file corrupt" when using Git</h1> <p>After <code>git init</code>, I added and committed a few files, made some changes, added and committed. Set up the git daemon (running under Cygwin on WinXP) and cloned the repository once. Now, I get this error with the cloned re...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,877
git
# How to resolve "Error: bad index – Fatal: index file corrupt" when using Git After `git init`, I added and committed a few files, made some changes, added and committed. Set up the git daemon (running under Cygwin on WinXP) and cloned the repository once. Now, I get this error with the cloned repository: ``` $ git ...
If the problem is with the index as **the staging area for commits** (i.e. `.git/index`), you can simply remove the index (make a backup copy if you want), and then restore index to version in the last commit: On OSX/Linux/Windows(With Git bash): ``` rm -f .git/index git reset ``` On Windows (with CMD and not git ba...
4850717
How to cancel a local git commit?
943
2011-01-31 12:14:48
<p>My issue is I have changed a file e.g.: README, added a new line '<em>this for my testing line</em>' and saved the file, then I issued the following commands:</p> <pre><code>git status # On branch master # Changed but not updated: # (use &quot;git add &lt;file&gt;...&quot; to update what will be committed) # (u...
1,310,146
457,036
2025-01-30 13:46:01
4,850,743
1,738
2011-01-31 12:17:08
81,071
2015-07-10 18:42:23
https://stackoverflow.com/q/4850717
https://stackoverflow.com/a/4850743
<p>Just use <code>git reset</code> without the <code>--hard</code> flag:</p> <pre><code>git reset HEAD~1 </code></pre> <p>PS: On Unix based systems you can use <code>HEAD^</code> which is equal to <code>HEAD~1</code>. On Windows <code>HEAD^</code> will not work because <code>^</code> signals a line continuation. So y...
<p>Just use <code>git reset</code> without the <code>--hard</code> flag:</p> <pre><code>git reset HEAD~1 </code></pre> <p>PS: On Unix based systems you can use <code>HEAD^</code> which is equal to <code>HEAD~1</code>. On Windows <code>HEAD^</code> will not work because <code>^</code> signals a line continuation. So y...
119, 51381, 53850
git, git-commit, git-reset
<h1>How to cancel a local git commit?</h1> <p>My issue is I have changed a file e.g.: README, added a new line '<em>this for my testing line</em>' and saved the file, then I issued the following commands:</p> <pre><code>git status # On branch master # Changed but not updated: # (use &quot;git add &lt;file&gt;...&quo...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,878
git
# How to cancel a local git commit? My issue is I have changed a file e.g.: README, added a new line '*this for my testing line*' and saved the file, then I issued the following commands: ``` git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (...
Just use `git reset` without the `--hard` flag: ``` git reset HEAD~1 ``` PS: On Unix based systems you can use `HEAD^` which is equal to `HEAD~1`. On Windows `HEAD^` will not work because `^` signals a line continuation. So your command prompt will just ask you `More?`.
3184555
Cleaning up old remote git branches
1,029
2010-07-06 08:14:50
<p>I work from two different computers (A and B) and store a common git remote in the dropbox directory.</p> <p>Let's say I have two branches, master and devel. Both are tracking their remote counterparts origin/master and origin/devel.</p> <p>Now while on computer A, I delete branch devel, on local and remote.</p> ...
602,288
174,527
2024-08-31 15:32:24
3,184,742
1,736
2010-07-06 08:45:46
46,058
2019-10-18 17:23:02
https://stackoverflow.com/q/3184555
https://stackoverflow.com/a/3184742
<p>First, what is the result of <code>git branch -a</code> on machine B?</p> <p>Second, you have already deleted <code>heads/devel</code> on <code>origin</code>, so that's why you can't delete it from machine B.</p> <p>Try</p> <pre><code>git branch -r -d origin/devel </code></pre> <p>or</p> <pre><code>git remote p...
<p>First, what is the result of <code>git branch -a</code> on machine B?</p> <p>Second, you have already deleted <code>heads/devel</code> on <code>origin</code>, so that's why you can't delete it from machine B.</p> <p>Try</p> <pre><code>git branch -r -d origin/devel </code></pre> <p>or</p> <pre><code>git remote p...
119, 76220
git, git-branch
<h1>Cleaning up old remote git branches</h1> <p>I work from two different computers (A and B) and store a common git remote in the dropbox directory.</p> <p>Let's say I have two branches, master and devel. Both are tracking their remote counterparts origin/master and origin/devel.</p> <p>Now while on computer A, I de...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,879
git
# Cleaning up old remote git branches I work from two different computers (A and B) and store a common git remote in the dropbox directory. Let's say I have two branches, master and devel. Both are tracking their remote counterparts origin/master and origin/devel. Now while on computer A, I delete branch devel, on l...
First, what is the result of `git branch -a` on machine B? Second, you have already deleted `heads/devel` on `origin`, so that's why you can't delete it from machine B. Try ``` git branch -r -d origin/devel ``` or ``` git remote prune origin ``` or ``` git fetch origin --prune ``` and feel free to add `--dry-ru...
957928
Is there a way to get the git root directory in one command?
1,045
2009-06-05 20:15:26
<p>Mercurial has a way of printing the root directory (that contains .hg) via</p> <pre><code>hg root </code></pre> <p>Is there something equivalent in git to get the directory that contains the .git directory?</p>
446,262
9,022
2025-03-08 12:15:10
957,978
1,731
2009-06-05 20:29:12
10,738
2023-11-10 14:44:23
https://stackoverflow.com/q/957928
https://stackoverflow.com/a/957978
<p>Yes:</p> <pre><code>git rev-parse --show-toplevel </code></pre> <p>If you want to replicate the Mercurial command more directly, you can create an <a href="https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases" rel="noreferrer">alias</a>:</p> <pre class="lang-bash prettyprint-override"><code>git config --global alia...
<p>Yes:</p> <pre><code>git rev-parse --show-toplevel </code></pre> <p>If you want to replicate the Mercurial command more directly, you can create an <a href="https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases" rel="noreferrer">alias</a>:</p> <pre class="lang-bash prettyprint-override"><code>git config --global alia...
119, 456
git, version-control
<h1>Is there a way to get the git root directory in one command?</h1> <p>Mercurial has a way of printing the root directory (that contains .hg) via</p> <pre><code>hg root </code></pre> <p>Is there something equivalent in git to get the directory that contains the .git directory?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,880
git
# Is there a way to get the git root directory in one command? Mercurial has a way of printing the root directory (that contains .hg) via ``` hg root ``` Is there something equivalent in git to get the directory that contains the .git directory?
Yes: ``` git rev-parse --show-toplevel ``` If you want to replicate the Mercurial command more directly, you can create an [alias](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases): ``` git config --global alias.root 'rev-parse --show-toplevel' ``` and now `git root` will function just as `hg root`. --- **No...
7206801
Is there any way to git checkout previous branch?
1,020
2011-08-26 15:09:11
<p>I sort of want the equivalent of <code>cd -</code> for git. If I am in branch <code>master</code> and I checkout <code>foo</code>, I would love to be able to type something like <code>git checkout -</code> to go back to <code>master</code>, and be able to type it again to return to <code>foo</code>.</p> <p>Does any...
159,561
10,771
2024-05-22 06:07:41
7,207,542
1,725
2011-08-26 16:05:01
389,146
2022-11-03 07:42:14
https://stackoverflow.com/q/7206801
https://stackoverflow.com/a/7207542
<p>From the <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.6.2.txt" rel="noreferrer">release notes for 1.6.2</a></p> <blockquote> <p><code>@{-1}</code> is a way to refer to the last branch you were on. This is<br /> accepted not only where an object name is expected, but anywhere a branch nam...
<p>From the <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.6.2.txt" rel="noreferrer">release notes for 1.6.2</a></p> <blockquote> <p><code>@{-1}</code> is a way to refer to the last branch you were on. This is<br /> accepted not only where an object name is expected, but anywhere a branch nam...
119, 37230
git, git-checkout
<h1>Is there any way to git checkout previous branch?</h1> <p>I sort of want the equivalent of <code>cd -</code> for git. If I am in branch <code>master</code> and I checkout <code>foo</code>, I would love to be able to type something like <code>git checkout -</code> to go back to <code>master</code>, and be able to ty...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,881
git
# Is there any way to git checkout previous branch? I sort of want the equivalent of `cd -` for git. If I am in branch `master` and I checkout `foo`, I would love to be able to type something like `git checkout -` to go back to `master`, and be able to type it again to return to `foo`. Does anything like this exist? ...
From the [release notes for 1.6.2](https://github.com/git/git/blob/master/Documentation/RelNotes/1.6.2.txt) > `@{-1}` is a way to refer to the last branch you were on. This is > accepted not only where an object name is expected, but anywhere a > branch name is expected and acts as if you typed the branch name. > ...
4878249
How to change the remote a branch is tracking?
1,074
2011-02-02 18:20:33
<p>The <code>central</code> repository had to be set up on a new server, so I created a new remote on my local repo, and pushed to that.</p> <p>But now when I do <code>git pull</code>, it claims I am up to date. It's wrong&mdash;it's telling me about the <em>old</em> remote branch, not the new one, which I know for a ...
923,671
187,581
2023-02-23 09:27:34
4,879,224
1,716
2011-02-02 19:59:55
416,626
2020-10-28 20:45:02
https://stackoverflow.com/q/4878249
https://stackoverflow.com/a/4879224
<h2>Using <strong>git v1.8.0</strong> or later:</h2> <pre class="lang-sh prettyprint-override"><code>git branch branch_name --set-upstream-to your_new_remote/branch_name </code></pre> <h2>Or you can use the <code>-u</code> switch</h2> <pre class="lang-sh prettyprint-override"><code>git branch branch_name -u your_new_re...
<h2>Using <strong>git v1.8.0</strong> or later:</h2> <pre class="lang-sh prettyprint-override"><code>git branch branch_name --set-upstream-to your_new_remote/branch_name </code></pre> <h2>Or you can use the <code>-u</code> switch</h2> <pre class="lang-sh prettyprint-override"><code>git branch branch_name -u your_new_re...
119
git
<h1>How to change the remote a branch is tracking?</h1> <p>The <code>central</code> repository had to be set up on a new server, so I created a new remote on my local repo, and pushed to that.</p> <p>But now when I do <code>git pull</code>, it claims I am up to date. It's wrong&mdash;it's telling me about the <em>old<...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,882
git
# How to change the remote a branch is tracking? The `central` repository had to be set up on a new server, so I created a new remote on my local repo, and pushed to that. But now when I do `git pull`, it claims I am up to date. It's wrong—it's telling me about the *old* remote branch, not the new one, which I know f...
## Using **git v1.8.0** or later: ``` git branch branch_name --set-upstream-to your_new_remote/branch_name ``` ## Or you can use the `-u` switch ``` git branch branch_name -u your_new_remote/branch_name ``` ### Using git **v1.7.12** or earlier ``` git branch --set-upstream branch_name your_new_remote/branch_name `...
1105253
How would I extract a single file (or changes to a file) from a git stash?
1,220
2009-07-09 17:12:11
<p>Is it possible to extract a single file or diff of a file from a git stash without popping the stash changeset off?</p>
502,961
26,630
2025-05-13 01:45:32
1,105,666
1,685
2009-07-09 18:21:11
46,058
2024-07-11 08:46:03
https://stackoverflow.com/q/1105253
https://stackoverflow.com/a/1105666
<p>On the <a href="http://git-scm.com/docs/git-stash" rel="noreferrer" title="git-stash - Stash the changes in a dirty working directory away">git stash</a> manpage you can read (in the &quot;Discussion&quot; section, just after &quot;Options&quot; description) that:</p> <blockquote> <p>A stash is represented as a...
<p>On the <a href="http://git-scm.com/docs/git-stash" rel="noreferrer" title="git-stash - Stash the changes in a dirty working directory away">git stash</a> manpage you can read (in the &quot;Discussion&quot; section, just after &quot;Options&quot; description) that:</p> <blockquote> <p>A stash is represented as a...
119, 13091
git, git-stash
<h1>How would I extract a single file (or changes to a file) from a git stash?</h1> <p>Is it possible to extract a single file or diff of a file from a git stash without popping the stash changeset off?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,883
git
# How would I extract a single file (or changes to a file) from a git stash? Is it possible to extract a single file or diff of a file from a git stash without popping the stash changeset off?
On the [git stash](http://git-scm.com/docs/git-stash "git-stash - Stash the changes in a dirty working directory away") manpage you can read (in the "Discussion" section, just after "Options" description) that: > A stash is represented as a commit whose tree records the state of the > working directory, and its first ...
12370714
Git: How do I list only local branches?
1,149
2012-09-11 13:21:19
<p><code>git branch -a</code> shows both remote and local branches.</p> <p><code>git branch -r</code> shows remote branches.</p> <p>Is there a way to list just the local branches?</p>
875,767
1,494,802
2025-10-18 16:29:14
12,370,765
1,673
2012-09-11 13:23:39
1,254,292
2020-12-28 21:38:09
https://stackoverflow.com/q/12370714
https://stackoverflow.com/a/12370765
<p>Just <code>git branch</code> without options.</p> <p>From the <a href="http://manpages.ubuntu.com/manpages/precise/en/man1/git-branch.1.html" rel="noreferrer">manpage</a>:</p> <blockquote> <p>With no arguments, existing branches are listed and the current branch will be highlighted with an asterisk.</p> </blockquote...
<p>Just <code>git branch</code> without options.</p> <p>From the <a href="http://manpages.ubuntu.com/manpages/precise/en/man1/git-branch.1.html" rel="noreferrer">manpage</a>:</p> <blockquote> <p>With no arguments, existing branches are listed and the current branch will be highlighted with an asterisk.</p> </blockquote...
119, 76220
git, git-branch
<h1>Git: How do I list only local branches?</h1> <p><code>git branch -a</code> shows both remote and local branches.</p> <p><code>git branch -r</code> shows remote branches.</p> <p>Is there a way to list just the local branches?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,884
git
# Git: How do I list only local branches? `git branch -a` shows both remote and local branches. `git branch -r` shows remote branches. Is there a way to list just the local branches?
Just `git branch` without options. From the [manpage](http://manpages.ubuntu.com/manpages/precise/en/man1/git-branch.1.html): > With no arguments, existing branches are listed and the current branch will be highlighted with an asterisk.
8044583
How can I move a tag on a git branch to a different commit?
1,256
2011-11-08 00:32:07
<p>I created a tag on the master branch called <code>v0.1</code> like this:</p> <pre><code>git tag -a v0.1 </code></pre> <p>But then I realized there were still some changes I needed to merge into master for release 0.1, so I did that. But now my <code>v0.1</code> tag is stuck on (to invoke the post-it note analogy) ...
660,055
698,102
2023-08-23 13:24:25
8,044,605
1,665
2011-11-08 00:34:45
893
2023-05-11 17:22:34
https://stackoverflow.com/q/8044583
https://stackoverflow.com/a/8044605
<p>Use the <code>-f</code> option to <a href="https://git-scm.com/docs/git-tag" rel="noreferrer"><code>git tag</code></a>:</p> <pre><code>-f --force Replace an existing tag with the given name (instead of failing) </code></pre> <p>You probably want to use <code>-f</code> in conjunction with <code>-a</code> to forc...
<p>Use the <code>-f</code> option to <a href="https://git-scm.com/docs/git-tag" rel="noreferrer"><code>git tag</code></a>:</p> <pre><code>-f --force Replace an existing tag with the given name (instead of failing) </code></pre> <p>You probably want to use <code>-f</code> in conjunction with <code>-a</code> to forc...
119, 60718
git, git-tag
<h1>How can I move a tag on a git branch to a different commit?</h1> <p>I created a tag on the master branch called <code>v0.1</code> like this:</p> <pre><code>git tag -a v0.1 </code></pre> <p>But then I realized there were still some changes I needed to merge into master for release 0.1, so I did that. But now my <c...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,886
git
# How can I move a tag on a git branch to a different commit? I created a tag on the master branch called `v0.1` like this: ``` git tag -a v0.1 ``` But then I realized there were still some changes I needed to merge into master for release 0.1, so I did that. But now my `v0.1` tag is stuck on (to invoke the post-it ...
Use the `-f` option to [`git tag`](https://git-scm.com/docs/git-tag): ``` -f --force Replace an existing tag with the given name (instead of failing) ``` You probably want to use `-f` in conjunction with `-a` to force-create an annotated tag instead of a non-annotated one. ## Example 1. Delete the tag on any r...
3065650
What's the simplest way to list conflicted files in Git?
965
2010-06-17 21:08:52
<p>I just need a plain list of <em>conflicted</em> files.</p> <p>Is there anything simpler than:</p> <pre><code>git ls-files -u | cut -f 2 | sort -u </code></pre> <p>or:</p> <pre><code>git ls-files -u | awk '{print $4}' | sort | uniq </code></pre> <p>I guess I could set up a handy <code>alias</code> for that, ho...
713,547
174,284
2024-07-01 04:10:54
10,874,862
1,646
2012-06-03 23:43:59
19,563
2022-05-23 14:10:30
https://stackoverflow.com/q/3065650
https://stackoverflow.com/a/10874862
<p>Use git diff, with <a href="https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---name-only" rel="noreferrer">name-only</a> to show only the names, and <a href="https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203" rel="noreferrer">diff-filter=U</a> to only include 'Un...
<p>Use git diff, with <a href="https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---name-only" rel="noreferrer">name-only</a> to show only the names, and <a href="https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203" rel="noreferrer">diff-filter=U</a> to only include 'Un...
119, 28897, 106113
git, git-merge, git-merge-conflict
<h1>What's the simplest way to list conflicted files in Git?</h1> <p>I just need a plain list of <em>conflicted</em> files.</p> <p>Is there anything simpler than:</p> <pre><code>git ls-files -u | cut -f 2 | sort -u </code></pre> <p>or:</p> <pre><code>git ls-files -u | awk '{print $4}' | sort | uniq </code></pre> ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,887
git
# What's the simplest way to list conflicted files in Git? I just need a plain list of *conflicted* files. Is there anything simpler than: ``` git ls-files -u | cut -f 2 | sort -u ``` or: ``` git ls-files -u | awk '{print $4}' | sort | uniq ``` I guess I could set up a handy `alias` for that, however was wonder...
Use git diff, with [name-only](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---name-only) to show only the names, and [diff-filter=U](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203) to only include 'Unmerged' files (optionally, [relative](https://git-scm.com/d...
20101834
pip install from git repo branch
1,230
2013-11-20 16:46:42
<p>Trying to <code>pip</code> install a repo's specific branch. Google tells me to</p> <pre><code>pip install https://github.com/user/repo.git@branch </code></pre> <p>The branch's name is <code>issue/34/oscar-0.6</code> so I did <code>pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0...
1,137,237
357,236
2025-10-31 02:53:10
20,101,940
1,642
2013-11-20 16:51:32
2,225,682
2021-12-23 08:01:43
https://stackoverflow.com/q/20101834
https://stackoverflow.com/a/20101940
<p>Prepend the url prefix <code>git+</code> (See <a href="https://pip.pypa.io/en/stable/topics/vcs-support/" rel="noreferrer">VCS Support</a>):</p> <pre><code>pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6 </code></pre> <p>And specify the branch name without the leading <code>...
<p>Prepend the url prefix <code>git+</code> (See <a href="https://pip.pypa.io/en/stable/topics/vcs-support/" rel="noreferrer">VCS Support</a>):</p> <pre><code>pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6 </code></pre> <p>And specify the branch name without the leading <code>...
16, 119, 5119
git, pip, python
<h1>pip install from git repo branch</h1> <p>Trying to <code>pip</code> install a repo's specific branch. Google tells me to</p> <pre><code>pip install https://github.com/user/repo.git@branch </code></pre> <p>The branch's name is <code>issue/34/oscar-0.6</code> so I did <code>pip install https://github.com/tangentlabs...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,888
git
# pip install from git repo branch Trying to `pip` install a repo's specific branch. Google tells me to ``` pip install https://github.com/user/repo.git@branch ``` The branch's name is `issue/34/oscar-0.6` so I did `pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0.6` but its retur...
Prepend the url prefix `git+` (See [VCS Support](https://pip.pypa.io/en/stable/topics/vcs-support/)): ``` pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6 ``` And specify the branch name without the leading `/`.
9903541
Finding diff between current and last version
941
2012-03-28 08:15:24
<p>Using Git, how can you find the difference between the current and the last version?</p> <pre><code>git diff last version:HEAD </code></pre>
822,062
277,603
2024-09-30 21:54:01
9,903,611
1,640
2012-03-28 08:19:39
930,271
2021-12-20 08:44:25
https://stackoverflow.com/q/9903541
https://stackoverflow.com/a/9903611
<p>I don't really understand the meaning of &quot;last version&quot;.</p> <p>As the previous commit can be accessed with HEAD^, I think that you are looking for something like:</p> <pre><code>git diff HEAD^ HEAD </code></pre> <p>That also can be applied for a :commithash</p> <pre><code>git diff $commithash^ $commithash...
<p>I don't really understand the meaning of &quot;last version&quot;.</p> <p>As the previous commit can be accessed with HEAD^, I think that you are looking for something like:</p> <pre><code>git diff HEAD^ HEAD </code></pre> <p>That also can be applied for a :commithash</p> <pre><code>git diff $commithash^ $commithash...
119, 9033
git, git-diff
<h1>Finding diff between current and last version</h1> <p>Using Git, how can you find the difference between the current and the last version?</p> <pre><code>git diff last version:HEAD </code></pre>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,889
git
# Finding diff between current and last version Using Git, how can you find the difference between the current and the last version? ``` git diff last version:HEAD ```
I don't really understand the meaning of "last version". As the previous commit can be accessed with HEAD^, I think that you are looking for something like: ``` git diff HEAD^ HEAD ``` That also can be applied for a :commithash ``` git diff $commithash^ $commithash ``` As of Git 1.8.5, `@` is an alias for `HEAD`, ...
16955980
Git merge hotfix branch into feature branch
1,360
2013-06-06 07:18:57
<p>Let’s say we have the following situation in Git:</p> <ol> <li><p>A created repository:</p> <pre><code>mkdir GitTest2 cd GitTest2 git init </code></pre></li> <li><p>Some modifications in the master take place and get committed:</p> <pre><code>echo "On Master" &gt; file git commit -a -m "Initial commit" </code></p...
1,908,616
61,855
2021-06-24 11:51:08
16,957,483
1,632
2013-06-06 08:42:35
1,627,406
2019-10-29 18:01:56
https://stackoverflow.com/q/16955980
https://stackoverflow.com/a/16957483
<p>How do we merge the master branch into the feature branch? Easy:</p> <pre><code>git checkout feature1 git merge master </code></pre> <p>There is no point in forcing a fast forward merge here, as it cannot be done. You committed both into the feature branch and the master branch. Fast forward is impossible now.</p>...
<p>How do we merge the master branch into the feature branch? Easy:</p> <pre><code>git checkout feature1 git merge master </code></pre> <p>There is no point in forcing a fast forward merge here, as it cannot be done. You committed both into the feature branch and the master branch. Fast forward is impossible now.</p>...
119, 28897, 40701, 64339, 76220
feature-branch, git, git-branch, git-flow, git-merge
<h1>Git merge hotfix branch into feature branch</h1> <p>Let’s say we have the following situation in Git:</p> <ol> <li><p>A created repository:</p> <pre><code>mkdir GitTest2 cd GitTest2 git init </code></pre></li> <li><p>Some modifications in the master take place and get committed:</p> <pre><code>echo "On Master" &...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,890
git
# Git merge hotfix branch into feature branch Let’s say we have the following situation in Git: 1. A created repository: ``` mkdir GitTest2 cd GitTest2 git init ``` 2. Some modifications in the master take place and get committed: ``` echo "On Master" > file git commit -a -m "Initial commit"...
How do we merge the master branch into the feature branch? Easy: ``` git checkout feature1 git merge master ``` There is no point in forcing a fast forward merge here, as it cannot be done. You committed both into the feature branch and the master branch. Fast forward is impossible now. Have a look at [GitFlow](http...
2318777
Undo a particular commit in Git that's been pushed to remote repos
1,053
2010-02-23 14:21:08
<p>What is the simplest way to undo a particular commit that is:</p> <ul> <li>not in the head or HEAD</li> <li>has been pushed to the remote.</li> </ul> <p>Because if it is not the latest commit,</p> <pre><code>git reset HEAD </code></pre> <p>doesn't work. And because it has been pushed to a remote,</p> <pre><code>git ...
652,138
55,562
2025-07-21 14:51:05
2,318,847
1,627
2010-02-23 14:31:16
24,762
2012-10-30 16:55:13
https://stackoverflow.com/q/2318777
https://stackoverflow.com/a/2318847
<p>Identify the hash of the commit, using <code>git log</code>, then use <code>git revert &lt;commit&gt;</code> to create a new commit that removes these changes. In a way, <code>git revert</code> is the converse of <code>git cherry-pick</code> -- the latter applies the patch to a branch that's missing it, the former ...
<p>Identify the hash of the commit, using <code>git log</code>, then use <code>git revert &lt;commit&gt;</code> to create a new commit that removes these changes. In a way, <code>git revert</code> is the converse of <code>git cherry-pick</code> -- the latter applies the patch to a branch that's missing it, the former ...
119, 456, 34403, 51381
git, git-reset, git-revert, version-control
<h1>Undo a particular commit in Git that's been pushed to remote repos</h1> <p>What is the simplest way to undo a particular commit that is:</p> <ul> <li>not in the head or HEAD</li> <li>has been pushed to the remote.</li> </ul> <p>Because if it is not the latest commit,</p> <pre><code>git reset HEAD </code></pre> <p>d...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,891
git
# Undo a particular commit in Git that's been pushed to remote repos What is the simplest way to undo a particular commit that is: - not in the head or HEAD - has been pushed to the remote. Because if it is not the latest commit, ``` git reset HEAD ``` doesn't work. And because it has been pushed to a remote, ```...
Identify the hash of the commit, using `git log`, then use `git revert <commit>` to create a new commit that removes these changes. In a way, `git revert` is the converse of `git cherry-pick` -- the latter applies the patch to a branch that's missing it, the former removes it from a branch that has it.
2528111
How can I calculate the number of lines changed between two commits in Git?
1,184
2010-03-27 04:02:58
<p>Is there any easy way to calculate the number of lines changed between two commits in Git?</p> <p>I know I can do a <code>git diff</code>, and count the lines, but this seems tedious. I'd also like to know how I can do this, including only my own commits in the line counts.</p>
620,241
139,685
2025-11-10 15:43:09
2,528,129
1,626
2010-03-27 04:14:51
119,963
2014-10-03 05:58:49
https://stackoverflow.com/q/2528111
https://stackoverflow.com/a/2528129
<p>You want the <code>--stat</code> option of <code>git diff</code>, or if you're looking to parse this in a script, the <code>--numstat</code> option.</p> <pre><code>git diff --stat &lt;commit-ish&gt; &lt;commit-ish&gt; </code></pre> <p><code>--stat</code> produces the human-readable output you're used to seeing aft...
<p>You want the <code>--stat</code> option of <code>git diff</code>, or if you're looking to parse this in a script, the <code>--numstat</code> option.</p> <pre><code>git diff --stat &lt;commit-ish&gt; &lt;commit-ish&gt; </code></pre> <p><code>--stat</code> produces the human-readable output you're used to seeing aft...
119
git
<h1>How can I calculate the number of lines changed between two commits in Git?</h1> <p>Is there any easy way to calculate the number of lines changed between two commits in Git?</p> <p>I know I can do a <code>git diff</code>, and count the lines, but this seems tedious. I'd also like to know how I can do this, includi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,892
git
# How can I calculate the number of lines changed between two commits in Git? Is there any easy way to calculate the number of lines changed between two commits in Git? I know I can do a `git diff`, and count the lines, but this seems tedious. I'd also like to know how I can do this, including only my own commits in ...
You want the `--stat` option of `git diff`, or if you're looking to parse this in a script, the `--numstat` option. ``` git diff --stat <commit-ish> <commit-ish> ``` `--stat` produces the human-readable output you're used to seeing after merges; `--numstat` produces a nice table layout that scripts can easily interpr...
1914579
Set up git to pull and push all branches
791
2009-12-16 13:09:52
<p>I'd like to push and pull all the branches by default, including the newly created ones.</p> <p>Is there a setting that I can define for it?</p> <p>Otherwise, when I add a new branch, locally and I want to pull it from the server, what is the simplest way to do it?</p> <p>I created a new branch with the same name...
357,078
55,562
2024-07-02 18:01:50
10,479,068
1,626
2012-05-07 08:39:52
1,319,088
2021-10-29 10:35:29
https://stackoverflow.com/q/1914579
https://stackoverflow.com/a/10479068
<p>The simplest way is to do:</p> <pre><code>git push --all origin </code></pre> <p>This will push tags and branches.</p>
<p>The simplest way is to do:</p> <pre><code>git push --all origin </code></pre> <p>This will push tags and branches.</p>
119, 456, 1879, 4236
branch, git, push, version-control
<h1>Set up git to pull and push all branches</h1> <p>I'd like to push and pull all the branches by default, including the newly created ones.</p> <p>Is there a setting that I can define for it?</p> <p>Otherwise, when I add a new branch, locally and I want to pull it from the server, what is the simplest way to do it?...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,893
git
# Set up git to pull and push all branches I'd like to push and pull all the branches by default, including the newly created ones. Is there a setting that I can define for it? Otherwise, when I add a new branch, locally and I want to pull it from the server, what is the simplest way to do it? I created a new branc...
The simplest way is to do: ``` git push --all origin ``` This will push tags and branches.
677436
How do I get the Git commit count?
1,052
2009-03-24 13:38:55
<p>I'd like to get the number of commits of my Git repository, a bit like SVN revision numbers.</p> <p>The goal is to use it as a unique, incrementing build number.</p> <p>I currently do like that, on Unix/Cygwin/msysGit:</p> <pre><code>git log --pretty=format:'' | wc -l </code></pre> <p>But I feel it's a bit of a ...
517,765
14,622
2024-09-25 19:39:26
4,061,706
1,619
2010-10-31 03:21:03
3,461
2023-08-29 16:22:20
https://stackoverflow.com/q/677436
https://stackoverflow.com/a/4061706
<p>To get a commit count for a revision (<code>HEAD</code>, <code>master</code>, a commit hash):</p> <pre><code>git rev-list --count &lt;revision&gt; </code></pre> <p>To get the commit count across all branches:</p> <pre><code>git rev-list --count --all </code></pre> <p>I recommend against using this for build identifi...
<p>To get a commit count for a revision (<code>HEAD</code>, <code>master</code>, a commit hash):</p> <pre><code>git rev-list --count &lt;revision&gt; </code></pre> <p>To get the commit count across all branches:</p> <pre><code>git rev-list --count --all </code></pre> <p>I recommend against using this for build identifi...
119, 1555, 1783
build-process, git, revision
<h1>How do I get the Git commit count?</h1> <p>I'd like to get the number of commits of my Git repository, a bit like SVN revision numbers.</p> <p>The goal is to use it as a unique, incrementing build number.</p> <p>I currently do like that, on Unix/Cygwin/msysGit:</p> <pre><code>git log --pretty=format:'' | wc -l <...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,894
git
# How do I get the Git commit count? I'd like to get the number of commits of my Git repository, a bit like SVN revision numbers. The goal is to use it as a unique, incrementing build number. I currently do like that, on Unix/Cygwin/msysGit: ``` git log --pretty=format:'' | wc -l ``` But I feel it's a bit of a hac...
To get a commit count for a revision (`HEAD`, `master`, a commit hash): ``` git rev-list --count <revision> ``` To get the commit count across all branches: ``` git rev-list --count --all ``` I recommend against using this for build identifier, but if you must, it's probably best to use the count for the branch you...
10237071
How to amend a commit without changing commit message (reusing the previous one)?
1,033
2012-04-19 21:28:45
<p>Is there a way to amend a commit without <code>vi</code> (or your <code>$EDITOR</code>) popping up with the option to modify your commit message, but simply reusing the previous message?</p>
422,747
714,112
2023-06-13 13:01:18
10,365,442
1,603
2012-04-28 16:33:42
1,363,110
2022-05-29 19:26:45
https://stackoverflow.com/q/10237071
https://stackoverflow.com/a/10365442
<p>Since Git <code>1.7.9</code> you can also use <code>git commit --amend --no-edit</code> to get your result.</p> <p>Note that this will not include metadata from the other commit such as the timestamp or tag, which may or may not be important to you.</p>
<p>Since Git <code>1.7.9</code> you can also use <code>git commit --amend --no-edit</code> to get your result.</p> <p>Note that this will not include metadata from the other commit such as the timestamp or tag, which may or may not be important to you.</p>
119, 5597, 30968, 53850
commit, git, git-amend, git-commit
<h1>How to amend a commit without changing commit message (reusing the previous one)?</h1> <p>Is there a way to amend a commit without <code>vi</code> (or your <code>$EDITOR</code>) popping up with the option to modify your commit message, but simply reusing the previous message?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,895
git
# How to amend a commit without changing commit message (reusing the previous one)? Is there a way to amend a commit without `vi` (or your `$EDITOR`) popping up with the option to modify your commit message, but simply reusing the previous message?
Since Git `1.7.9` you can also use `git commit --amend --no-edit` to get your result. Note that this will not include metadata from the other commit such as the timestamp or tag, which may or may not be important to you.
750172
How do I change the author and committer name/email for multiple commits?
3,219
2009-04-15 03:09:24
<p>How do I change the author for a range of commits?</p>
1,313,417
802
2025-09-16 14:41:33
750,182
1,594
2009-04-15 03:16:42
825
2022-03-20 00:20:52
https://stackoverflow.com/q/750172
https://stackoverflow.com/a/750182
<blockquote> <p>This answer uses <code>git-filter-branch</code>, for which <a href="https://git-scm.com/docs/git-filter-branch" rel="noreferrer">the docs</a> now give this warning:</p> <p>git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the intended history rewrite (and can leave y...
<blockquote> <p>This answer uses <code>git-filter-branch</code>, for which <a href="https://git-scm.com/docs/git-filter-branch" rel="noreferrer">the docs</a> now give this warning:</p> <p>git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the intended history rewrite (and can leave y...
119, 456, 46509, 91259
git, git-filter-branch, git-rewrite-history, version-control
<h1>How do I change the author and committer name/email for multiple commits?</h1> <p>How do I change the author for a range of commits?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,896
git
# How do I change the author and committer name/email for multiple commits? How do I change the author for a range of commits?
> This answer uses `git-filter-branch`, for which [the docs](https://git-scm.com/docs/git-filter-branch) now give this warning: > > git filter-branch has a plethora of pitfalls that can produce non-obvious manglings of the intended history rewrite (and can leave you with little time to investigate such problems since i...
24290358
Remove a folder from git tracking
769
2014-06-18 16:10:23
<p>I need to exclude a folder (name uploads) from tracking. I tried to run</p> <pre><code>git rm -r --cached wordpress/wp-content/uploads </code></pre> <p>and after that I added the path to .gitignore</p> <pre><code>/wordpress/wp-content/uploads </code></pre> <p>but when I ran <code>git status</code> they show up a...
535,637
2,635,490
2025-02-02 07:05:41
30,360,954
1,580
2015-05-20 21:46:22
29,613
2015-05-21 07:34:02
https://stackoverflow.com/q/24290358
https://stackoverflow.com/a/30360954
<p>I came across this question while Googling for "git remove folder from tracking". The OP's question lead me to the answer. I am summarizing it here for future generations.</p> <p><strong>Question</strong></p> <p>How do I remove a folder from my git repository without deleting it from my local machine (i.e., develo...
<p>I came across this question while Googling for "git remove folder from tracking". The OP's question lead me to the answer. I am summarizing it here for future generations.</p> <p><strong>Question</strong></p> <p>How do I remove a folder from my git repository without deleting it from my local machine (i.e., develo...
119, 112901
git, git-rm
<h1>Remove a folder from git tracking</h1> <p>I need to exclude a folder (name uploads) from tracking. I tried to run</p> <pre><code>git rm -r --cached wordpress/wp-content/uploads </code></pre> <p>and after that I added the path to .gitignore</p> <pre><code>/wordpress/wp-content/uploads </code></pre> <p>but when I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,898
git
# Remove a folder from git tracking I need to exclude a folder (name uploads) from tracking. I tried to run ``` git rm -r --cached wordpress/wp-content/uploads ``` and after that I added the path to .gitignore ``` /wordpress/wp-content/uploads ``` but when I ran `git status` they show up as deleted. If I try to co...
I came across this question while Googling for "git remove folder from tracking". The OP's question lead me to the answer. I am summarizing it here for future generations. **Question** How do I remove a folder from my git repository without deleting it from my local machine (i.e., development environment)? **Answer*...
40503417
How can I add a file to the last commit in Git?
778
2016-11-09 09:19:03
<p>Sometimes after I did a commit, I found out that I left out a file which should also be included in the commit, but was actually not. I often committed again:</p> <pre><code>git add the_left_out_file git commit &quot;include the file which should be added in the last commit&quot; </code></pre> <p>I think it might no...
425,719
1,031,769
2021-11-28 02:38:38
40,503,483
1,578
2016-11-09 09:22:46
1,892,091
2021-11-28 02:38:38
https://stackoverflow.com/q/40503417
https://stackoverflow.com/a/40503483
<p>Yes, there's a command, <code>git commit --amend</code>, which is used to &quot;fix&quot; the last commit.</p> <p>In your case, it would be called as:</p> <pre><code>git add the_left_out_file git commit --amend --no-edit </code></pre> <p>The <em>--no-edit</em> flag allows to make an amendment to the commit without c...
<p>Yes, there's a command, <code>git commit --amend</code>, which is used to &quot;fix&quot; the last commit.</p> <p>In your case, it would be called as:</p> <pre><code>git add the_left_out_file git commit --amend --no-edit </code></pre> <p>The <em>--no-edit</em> flag allows to make an amendment to the commit without c...
119
git
<h1>How can I add a file to the last commit in Git?</h1> <p>Sometimes after I did a commit, I found out that I left out a file which should also be included in the commit, but was actually not. I often committed again:</p> <pre><code>git add the_left_out_file git commit &quot;include the file which should be added in t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,899
git
# How can I add a file to the last commit in Git? Sometimes after I did a commit, I found out that I left out a file which should also be included in the commit, but was actually not. I often committed again: ``` git add the_left_out_file git commit "include the file which should be added in the last commit" ``` I t...
Yes, there's a command, `git commit --amend`, which is used to "fix" the last commit. In your case, it would be called as: ``` git add the_left_out_file git commit --amend --no-edit ``` The *--no-edit* flag allows to make an amendment to the commit without changing the commit message. **Warning** You should never ...
13064613
How to prune local tracking branches that do not exist on remote anymore?
1,454
2012-10-25 08:31:13
<p>With <code>git remote prune origin</code> I can remove the local branches that are not on the remote any more.</p> <p>But I also want to remove local branches that were created from those remote branches (a check if they are unmerged would be nice).</p> <p>How can I do this?</p>
871,739
288,568
2025-05-14 23:47:45
17,029,936
1,576
2013-06-10 17:54:00
498,699
2024-09-30 14:43:29
https://stackoverflow.com/q/13064613
https://stackoverflow.com/a/17029936
<p>After pruning, you can get the list of remote branches with <code>git branch -r</code>. The list of branches with their remote tracking branch can be retrieved with <code>git branch -vv</code>. So using these two lists you can find the remote tracking branches that are not in the list of remotes.</p> <p>This line ...
<p>After pruning, you can get the list of remote branches with <code>git branch -r</code>. The list of branches with their remote tracking branch can be retrieved with <code>git branch -vv</code>. So using these two lists you can find the remote tracking branches that are not in the list of remotes.</p> <p>This line ...
119, 76220
git, git-branch
<h1>How to prune local tracking branches that do not exist on remote anymore?</h1> <p>With <code>git remote prune origin</code> I can remove the local branches that are not on the remote any more.</p> <p>But I also want to remove local branches that were created from those remote branches (a check if they are unmerge...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,900
git
# How to prune local tracking branches that do not exist on remote anymore? With `git remote prune origin` I can remove the local branches that are not on the remote any more. But I also want to remove local branches that were created from those remote branches (a check if they are unmerged would be nice). How can I...
After pruning, you can get the list of remote branches with `git branch -r`. The list of branches with their remote tracking branch can be retrieved with `git branch -vv`. So using these two lists you can find the remote tracking branches that are not in the list of remotes. This line should do the trick (requires `ba...
3701404
How to list all commits that changed a specific file?
1,219
2010-09-13 14:37:00
<p>Is there a way to list all commits that changed a specific file?</p>
499,105
136,857
2024-02-07 03:23:24
8,808,453
1,571
2012-01-10 18:26:04
289,122
2019-12-20 14:33:26
https://stackoverflow.com/q/3701404
https://stackoverflow.com/a/8808453
<p>The <code>--follow</code> works for a particular file</p> <pre><code>git log --follow -- filename </code></pre> <p><strong>Difference to other solutions given</strong></p> <p>Note that other solutions include <code>git log path</code> (without the <code>--follow</code>). That approach is handy if you want to trac...
<p>The <code>--follow</code> works for a particular file</p> <pre><code>git log --follow -- filename </code></pre> <p><strong>Difference to other solutions given</strong></p> <p>Note that other solutions include <code>git log path</code> (without the <code>--follow</code>). That approach is handy if you want to trac...
119, 5597
commit, git
<h1>How to list all commits that changed a specific file?</h1> <p>Is there a way to list all commits that changed a specific file?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,901
git
# How to list all commits that changed a specific file? Is there a way to list all commits that changed a specific file?
The `--follow` works for a particular file ``` git log --follow -- filename ``` **Difference to other solutions given** Note that other solutions include `git log path` (without the `--follow`). That approach is handy if you want to track e.g. changes in a **directory**, but **stumbles when files were renamed** (thu...
1549146
Git: Find the most recent common ancestor of two branches
1,250
2009-10-10 21:43:09
<p>How to find the most recent common ancestor of two Git branches?</p>
301,718
8,965
2025-08-22 08:47:44
1,549,155
1,570
2009-10-10 21:47:38
19,563
2022-10-12 12:06:05
https://stackoverflow.com/q/1549146
https://stackoverflow.com/a/1549155
<p>You are looking for <a href="https://git-scm.com/docs/git-merge-base" rel="noreferrer"><code>git merge-base</code></a>. Usage:</p> <pre><code>$ git merge-base branch2 branch3 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2 </code></pre>
<p>You are looking for <a href="https://git-scm.com/docs/git-merge-base" rel="noreferrer"><code>git merge-base</code></a>. Usage:</p> <pre><code>$ git merge-base branch2 branch3 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2 </code></pre>
119, 76220
git, git-branch
<h1>Git: Find the most recent common ancestor of two branches</h1> <p>How to find the most recent common ancestor of two Git branches?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,902
git
# Git: Find the most recent common ancestor of two branches How to find the most recent common ancestor of two Git branches?
You are looking for [`git merge-base`](https://git-scm.com/docs/git-merge-base). Usage: ``` $ git merge-base branch2 branch3 050dc022f3a65bdc78d97e2b1ac9b595a924c3f2 ```
1910082
git stash apply version
928
2009-12-15 20:14:32
<p>I have 2 branches: master | design</p> <p>Working in design I did a stash and switched to master, made some adjustments. Switched back to design and did a <code>stash apply</code> only to lose all my changes in the design branch.</p> <p>I am hoping all my work is within a stash as I have not cleared or removed the...
1,118,000
99,877
2022-06-21 10:06:55
1,910,142
1,567
2009-12-15 20:23:52
85,134
2019-04-17 12:41:17
https://stackoverflow.com/q/1910082
https://stackoverflow.com/a/1910142
<p>The keys into the stash are actually the <code>stash@{n}</code> items on the left. So try: </p> <pre><code>git stash apply stash@{0} </code></pre> <p>(note that in some shells you need to quote <code>"stash@{0}"</code>, like zsh, fish and powershell).</p> <p>Since version 2.11, it's pretty easy, you can use the N...
<p>The keys into the stash are actually the <code>stash@{n}</code> items on the left. So try: </p> <pre><code>git stash apply stash@{0} </code></pre> <p>(note that in some shells you need to quote <code>"stash@{0}"</code>, like zsh, fish and powershell).</p> <p>Since version 2.11, it's pretty easy, you can use the N...
119, 13091
git, git-stash
<h1>git stash apply version</h1> <p>I have 2 branches: master | design</p> <p>Working in design I did a stash and switched to master, made some adjustments. Switched back to design and did a <code>stash apply</code> only to lose all my changes in the design branch.</p> <p>I am hoping all my work is within a stash as ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,903
git
# git stash apply version I have 2 branches: master | design Working in design I did a stash and switched to master, made some adjustments. Switched back to design and did a `stash apply` only to lose all my changes in the design branch. I am hoping all my work is within a stash as I have not cleared or removed thes...
The keys into the stash are actually the `stash@{n}` items on the left. So try: ``` git stash apply stash@{0} ``` (note that in some shells you need to quote `"stash@{0}"`, like zsh, fish and powershell). Since version 2.11, it's pretty easy, you can use the N stack number instead of using `stash@{n}`. So now instea...
4950725
How can I see which Git branches are tracking which remote / upstream branch?
1,121
2011-02-09 21:30:46
<p>I know I can do <code>git branch --all</code>, and that shows me both local and remote branches, but it's not that useful in showing me the relationships between them.</p> <p>How do I list branches in a way that shows which local branch is tracking which remote?</p>
680,789
187,581
2025-07-21 11:50:03
4,952,368
1,554
2011-02-10 01:02:39
119,963
2025-01-27 12:45:52
https://stackoverflow.com/q/4950725
https://stackoverflow.com/a/4952368
<p>Very much a porcelain command, not good if you want this for scripting:</p> <pre><code>git branch -vv # doubly verbose! </code></pre> <p>Note that with git 1.8.3, that upstream branch is displayed in <strong>blue</strong> (see &quot;<a href="https://stackoverflow.com/a/16162827/6309">What is this branch tracking (...
<p>Very much a porcelain command, not good if you want this for scripting:</p> <pre><code>git branch -vv # doubly verbose! </code></pre> <p>Note that with git 1.8.3, that upstream branch is displayed in <strong>blue</strong> (see &quot;<a href="https://stackoverflow.com/a/16162827/6309">What is this branch tracking (...
119
git
<h1>How can I see which Git branches are tracking which remote / upstream branch?</h1> <p>I know I can do <code>git branch --all</code>, and that shows me both local and remote branches, but it's not that useful in showing me the relationships between them.</p> <p>How do I list branches in a way that shows which local...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,904
git
# How can I see which Git branches are tracking which remote / upstream branch? I know I can do `git branch --all`, and that shows me both local and remote branches, but it's not that useful in showing me the relationships between them. How do I list branches in a way that shows which local branch is tracking which r...
Very much a porcelain command, not good if you want this for scripting: ``` git branch -vv # doubly verbose! ``` Note that with git 1.8.3, that upstream branch is displayed in **blue** (see "[What is this branch tracking (if anything) in git?](https://stackoverflow.com/a/16162827/6309)") --- If you want clean out...
19730565
How to remove files from git staging area?
1,335
2013-11-01 16:03:45
<p>I made changes to some of my files in my local repo, and then I did <code>git add -A</code> which I think added too many files to the staging area. How can I delete all the files from the staging area?</p> <p>After I do that, I'll just manually do <code>git add "filename"</code>.</p>
1,698,644
1,497,454
2025-12-06 22:26:40
19,730,687
1,537
2013-11-01 16:10:11
10,556
2014-05-09 15:10:27
https://stackoverflow.com/q/19730565
https://stackoverflow.com/a/19730687
<p>You can unstage files from the index using</p> <pre><code>git reset HEAD -- path/to/file </code></pre> <p>Just like <code>git add</code>, you can unstage files recursively by directory and so forth, so to unstage everything at once, run this from the root directory of your repository:</p> <pre><code>git reset HEA...
<p>You can unstage files from the index using</p> <pre><code>git reset HEAD -- path/to/file </code></pre> <p>Just like <code>git add</code>, you can unstage files recursively by directory and so forth, so to unstage everything at once, run this from the root directory of your repository:</p> <pre><code>git reset HEA...
119
git
<h1>How to remove files from git staging area?</h1> <p>I made changes to some of my files in my local repo, and then I did <code>git add -A</code> which I think added too many files to the staging area. How can I delete all the files from the staging area?</p> <p>After I do that, I'll just manually do <code>git add "f...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,905
git
# How to remove files from git staging area? I made changes to some of my files in my local repo, and then I did `git add -A` which I think added too many files to the staging area. How can I delete all the files from the staging area? After I do that, I'll just manually do `git add "filename"`.
You can unstage files from the index using ``` git reset HEAD -- path/to/file ``` Just like `git add`, you can unstage files recursively by directory and so forth, so to unstage everything at once, run this from the root directory of your repository: ``` git reset HEAD -- . ``` Also, for future reference, the outpu...
9529078
How do I use 'git reset --hard HEAD' to revert to a previous commit?
1,321
2012-03-02 06:36:06
<p>I know that Git tracks changes I make to my application, and holds on to them until I commit the changes.</p> <p>To revert to a previous commit, I used:</p> <pre><code>$ git reset --hard HEAD HEAD is now at 820f417 micro </code></pre> <p>How do I then revert the files on my hard drive back to that previous commit?<...
5,302,555
1,241,571
2022-08-02 22:07:14
9,530,204
1,519
2012-03-02 08:32:00
223,092
2018-09-10 19:06:43
https://stackoverflow.com/q/9529078
https://stackoverflow.com/a/9530204
<p>First, it's always worth noting that <code>git reset --hard</code> is a potentially dangerous command, since it throws away all your uncommitted changes. For safety, you should always check that the output of <code>git status</code> is clean (that is, empty) before using it.</p> <p>Initially you say the following:<...
<p>First, it's always worth noting that <code>git reset --hard</code> is a potentially dangerous command, since it throws away all your uncommitted changes. For safety, you should always check that the output of <code>git status</code> is clean (that is, empty) before using it.</p> <p>Initially you say the following:<...
119, 17492, 34403, 51381
git, git-reset, git-revert, head
<h1>How do I use 'git reset --hard HEAD' to revert to a previous commit?</h1> <p>I know that Git tracks changes I make to my application, and holds on to them until I commit the changes.</p> <p>To revert to a previous commit, I used:</p> <pre><code>$ git reset --hard HEAD HEAD is now at 820f417 micro </code></pre> <p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,907
git
# How do I use 'git reset --hard HEAD' to revert to a previous commit? I know that Git tracks changes I make to my application, and holds on to them until I commit the changes. To revert to a previous commit, I used: ``` $ git reset --hard HEAD HEAD is now at 820f417 micro ``` How do I then revert the files on my ...
First, it's always worth noting that `git reset --hard` is a potentially dangerous command, since it throws away all your uncommitted changes. For safety, you should always check that the output of `git status` is clean (that is, empty) before using it. Initially you say the following: > So I know that Git tracks cha...
2569459
Git: Create a branch from unstaged/uncommitted changes on master
1,256
2010-04-02 22:09:59
<p>Context: I'm working on master adding a simple feature. After a few minutes I realize it was not so simple and it should have been better to work into a new branch.</p> <p>This always happens to me and I have no idea how to switch to another branch and take all these uncommited changes with me leaving the master br...
481,259
62,368
2021-05-12 10:12:49
2,569,513
1,516
2010-04-02 22:25:50
108,802
2021-05-12 10:12:49
https://stackoverflow.com/q/2569459
https://stackoverflow.com/a/2569513
<p>No need to stash.</p> <h1>Update 2020 / Git 2.23</h1> <hr /> <p>Git 2.23 adds the new <code>switch</code> subcommand, in an attempt to clear some of the confusion caused by the overloaded usage of <code>checkout</code> (switching branches, restoring files, detaching HEAD, etc.)</p> <p>Starting with this version of G...
<p>No need to stash.</p> <h1>Update 2020 / Git 2.23</h1> <hr /> <p>Git 2.23 adds the new <code>switch</code> subcommand, in an attempt to clear some of the confusion caused by the overloaded usage of <code>checkout</code> (switching branches, restoring files, detaching HEAD, etc.)</p> <p>Starting with this version of G...
119, 13091
git, git-stash
<h1>Git: Create a branch from unstaged/uncommitted changes on master</h1> <p>Context: I'm working on master adding a simple feature. After a few minutes I realize it was not so simple and it should have been better to work into a new branch.</p> <p>This always happens to me and I have no idea how to switch to another ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,908
git
# Git: Create a branch from unstaged/uncommitted changes on master Context: I'm working on master adding a simple feature. After a few minutes I realize it was not so simple and it should have been better to work into a new branch. This always happens to me and I have no idea how to switch to another branch and take ...
No need to stash. # Update 2020 / Git 2.23 --- Git 2.23 adds the new `switch` subcommand, in an attempt to clear some of the confusion caused by the overloaded usage of `checkout` (switching branches, restoring files, detaching HEAD, etc.) Starting with this version of Git, replace the `git checkout` command below ...
10510462
Force "git push" to overwrite remote files
1,169
2012-05-09 05:45:38
<p>I want to push my local files, and have them on a remote repo, without having to deal with merge conflicts. I just want my local version to have priority over the remote one.</p> <p>How can I do this with Git?</p>
1,325,903
47,633
2023-10-24 07:44:26
10,510,482
1,505
2012-05-09 05:48:23
591,166
2015-08-22 04:43:05
https://stackoverflow.com/q/10510462
https://stackoverflow.com/a/10510482
<p>You should be able to force your local revision to the remote repo by using </p> <pre><code>git push -f &lt;remote&gt; &lt;branch&gt; </code></pre> <p>(e.g. <code>git push -f origin master</code>). Leaving off <code>&lt;remote&gt;</code> and <code>&lt;branch&gt;</code> will force push all local branches that have ...
<p>You should be able to force your local revision to the remote repo by using </p> <pre><code>git push -f &lt;remote&gt; &lt;branch&gt; </code></pre> <p>(e.g. <code>git push -f origin master</code>). Leaving off <code>&lt;remote&gt;</code> and <code>&lt;branch&gt;</code> will force push all local branches that have ...
119, 28898
git, git-push
<h1>Force "git push" to overwrite remote files</h1> <p>I want to push my local files, and have them on a remote repo, without having to deal with merge conflicts. I just want my local version to have priority over the remote one.</p> <p>How can I do this with Git?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,911
git
# Force "git push" to overwrite remote files I want to push my local files, and have them on a remote repo, without having to deal with merge conflicts. I just want my local version to have priority over the remote one. How can I do this with Git?
You should be able to force your local revision to the remote repo by using ``` git push -f <remote> <branch> ``` (e.g. `git push -f origin master`). Leaving off `<remote>` and `<branch>` will force push all local branches that have set `--set-upstream`. Just be warned, if other people are sharing this repository th...
8570636
Change Folder Name During Clone
803
2011-12-20 04:00:12
<p>When I clone something, it creates a folder with the same name as the app on my computer.</p> <p>For example, doing this clone creates a long &quot;sign-in-with-twitter&quot; folder:</p> <pre><code>git clone https://github.com/sferik/sign-in-with-twitter.git </code></pre> <p>Is there a way to specify a custom name?<...
486,013
577,455
2024-05-20 14:06:57
8,570,660
1,492
2011-12-20 04:04:05
310,833
2024-01-30 18:53:18
https://stackoverflow.com/q/8570636
https://stackoverflow.com/a/8570660
<p>You can do this:</p> <pre><code>git clone https://github.com/sferik/sign-in-with-twitter.git signin # or git clone git@github.com:sferik/sign-in-with-twitter.git signin </code></pre> <p><a href="https://git-scm.com/docs/git-clone" rel="noreferrer">refer to the manual here</a></p>
<p>You can do this:</p> <pre><code>git clone https://github.com/sferik/sign-in-with-twitter.git signin # or git clone git@github.com:sferik/sign-in-with-twitter.git signin </code></pre> <p><a href="https://git-scm.com/docs/git-clone" rel="noreferrer">refer to the manual here</a></p>
119, 34099
git, git-clone
<h1>Change Folder Name During Clone</h1> <p>When I clone something, it creates a folder with the same name as the app on my computer.</p> <p>For example, doing this clone creates a long &quot;sign-in-with-twitter&quot; folder:</p> <pre><code>git clone https://github.com/sferik/sign-in-with-twitter.git </code></pre> <p>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,912
git
# Change Folder Name During Clone When I clone something, it creates a folder with the same name as the app on my computer. For example, doing this clone creates a long "sign-in-with-twitter" folder: ``` git clone https://github.com/sferik/sign-in-with-twitter.git ``` Is there a way to specify a custom name?
You can do this: ``` git clone https://github.com/sferik/sign-in-with-twitter.git signin # or git clone git@github.com:sferik/sign-in-with-twitter.git signin ``` [refer to the manual here](https://git-scm.com/docs/git-clone)
19663093
Apply .gitignore on an existing repository already tracking large number of files
567
2013-10-29 15:50:12
<p>I have an existing Visual Studio project in my repository. I recently added a .gitignore file under my project and I assume that tells Git to ignore the files listed in the file. </p> <p>My problem is that all those files are already being tracked and as far as I know Git will not ignore a file that was already tra...
495,987
597,076
2024-08-05 14:47:56
19,757,964
1,488
2013-11-03 20:51:31
597,076
2021-10-23 15:09:08
https://stackoverflow.com/q/19663093
https://stackoverflow.com/a/19757964
<p>This <a href="https://stackoverflow.com/questions/1139762/gitignore-file-not-ignoring">answer</a> solved my problem:</p> <p>First of all, <strong>commit all pending changes.</strong></p> <p>Then run this command:</p> <pre><code>git rm -r --cached . </code></pre> <p>This removes everything from the index, then just r...
<p>This <a href="https://stackoverflow.com/questions/1139762/gitignore-file-not-ignoring">answer</a> solved my problem:</p> <p>First of all, <strong>commit all pending changes.</strong></p> <p>Then run this command:</p> <pre><code>git rm -r --cached . </code></pre> <p>This removes everything from the index, then just r...
119, 25056
git, gitignore
<h1>Apply .gitignore on an existing repository already tracking large number of files</h1> <p>I have an existing Visual Studio project in my repository. I recently added a .gitignore file under my project and I assume that tells Git to ignore the files listed in the file. </p> <p>My problem is that all those files are...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,913
git
# Apply .gitignore on an existing repository already tracking large number of files I have an existing Visual Studio project in my repository. I recently added a .gitignore file under my project and I assume that tells Git to ignore the files listed in the file. My problem is that all those files are already being tr...
This [answer](https://stackoverflow.com/questions/1139762/gitignore-file-not-ignoring) solved my problem: First of all, **commit all pending changes.** Then run this command: ``` git rm -r --cached . ``` This removes everything from the index, then just run: ``` git add . ``` Commit it: ``` git commit -m ".gitig...
4269922
Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly
855
2010-11-24 17:51:13
<p>I'm attempting to deploy my code to heroku with the following command line:</p> <pre><code>git push heroku master </code></pre> <p>but get the following error:</p> <pre><code>Permission denied (publickey). fatal: The remote end hung up unexpectedly </code></pre> <p>I have already uploaded my public SSH key, but ...
225,902
461,294
2025-01-22 18:44:37
6,059,231
1,482
2011-05-19 13:15:00
506,570
2016-11-27 00:02:51
https://stackoverflow.com/q/4269922
https://stackoverflow.com/a/6059231
<p>You have to upload your public key to Heroku:</p> <pre><code>heroku keys:add ~/.ssh/id_rsa.pub </code></pre> <p>If you don't have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use: </p> <pre><code>heroku keys:add </code></pre> <p>To clear all your previous keys do :</...
<p>You have to upload your public key to Heroku:</p> <pre><code>heroku keys:add ~/.ssh/id_rsa.pub </code></pre> <p>If you don't have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use: </p> <pre><code>heroku keys:add </code></pre> <p>To clear all your previous keys do :</...
119, 190, 8279, 57931
deployment, git, heroku, public-key
<h1>Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly</h1> <p>I'm attempting to deploy my code to heroku with the following command line:</p> <pre><code>git push heroku master </code></pre> <p>but get the following error:</p> <pre><code>Permission denied (publickey)...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,914
git
# Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly I'm attempting to deploy my code to heroku with the following command line: ``` git push heroku master ``` but get the following error: ``` Permission denied (publickey). fatal: The remote end hung up unexpectedly...
You have to upload your public key to Heroku: ``` heroku keys:add ~/.ssh/id_rsa.pub ``` If you don't have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use: ``` heroku keys:add ``` To clear all your previous keys do : ``` heroku keys:clear ``` To display all your exist...
881092
How to merge a specific commit in Git
1,381
2009-05-19 05:27:34
<p>I have forked a branch from a repository in GitHub and committed something specific to me. Now I found the original repository had a good feature which was at <code>HEAD</code>.</p> <p>I want to merge it only without previous commits. What should I do? I know how to merge all commits:</p> <pre><code>git branch -b ...
1,290,822
109,169
2023-03-05 11:54:54
881,112
1,475
2009-05-19 05:35:40
6,309
2023-01-31 14:04:08
https://stackoverflow.com/q/881092
https://stackoverflow.com/a/881112
<p><a href="https://git-scm.com/docs/git-cherry-pick" rel="noreferrer"><code>git cherry-pick</code></a> should be your answer here.</p> <blockquote> <p>Apply the change introduced by an existing commit.</p> </blockquote> <p>Do not forget to read <a href="https://stackoverflow.com/users/36723/bdonlan">bdonlan</a>'s answ...
<p><a href="https://git-scm.com/docs/git-cherry-pick" rel="noreferrer"><code>git cherry-pick</code></a> should be your answer here.</p> <blockquote> <p>Apply the change introduced by an existing commit.</p> </blockquote> <p>Do not forget to read <a href="https://stackoverflow.com/users/36723/bdonlan">bdonlan</a>'s answ...
119, 717
git, merge
<h1>How to merge a specific commit in Git</h1> <p>I have forked a branch from a repository in GitHub and committed something specific to me. Now I found the original repository had a good feature which was at <code>HEAD</code>.</p> <p>I want to merge it only without previous commits. What should I do? I know how to me...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,915
git
# How to merge a specific commit in Git I have forked a branch from a repository in GitHub and committed something specific to me. Now I found the original repository had a good feature which was at `HEAD`. I want to merge it only without previous commits. What should I do? I know how to merge all commits: ``` git b...
[`git cherry-pick`](https://git-scm.com/docs/git-cherry-pick) should be your answer here. > Apply the change introduced by an existing commit. Do not forget to read [bdonlan](https://stackoverflow.com/users/36723/bdonlan)'s answer about the consequence of cherry-picking in this post: ["Pull all commits from a branc...
2221658
What is the difference between HEAD^ and HEAD~ in Git?
1,293
2010-02-08 12:56:42
<p><code>HEAD^</code> (caret) and <code>HEAD~</code> (tilde) are both used to obtain a parent commit of <code>HEAD</code>. They can also end in numbers, e.g. <code>HEAD^2</code> and <code>HEAD~3</code>. They seem similar. What are the differences?</p>
392,156
227,171
2025-03-26 20:53:56
2,222,920
1,452
2010-02-08 16:06:54
123,109
2024-09-19 20:43:40
https://stackoverflow.com/q/2221658
https://stackoverflow.com/a/2222920
<h2>Rules of thumb</h2> <ul> <li><code>&lt;rev&gt;~&lt;n&gt;</code> goes backward <em>n</em> parents from <em>rev</em>, selecting the first parent each time.</li> <li>Use <code>&lt;rev&gt;^&lt;n&gt;</code> to select the <em>n</em>-th immediate parent of merge commit <em>rev</em>.</li> <li>Use <code>~</code> most of the...
<h2>Rules of thumb</h2> <ul> <li><code>&lt;rev&gt;~&lt;n&gt;</code> goes backward <em>n</em> parents from <em>rev</em>, selecting the first parent each time.</li> <li>Use <code>&lt;rev&gt;^&lt;n&gt;</code> to select the <em>n</em>-th immediate parent of merge commit <em>rev</em>.</li> <li>Use <code>~</code> most of the...
119
git
<h1>What is the difference between HEAD^ and HEAD~ in Git?</h1> <p><code>HEAD^</code> (caret) and <code>HEAD~</code> (tilde) are both used to obtain a parent commit of <code>HEAD</code>. They can also end in numbers, e.g. <code>HEAD^2</code> and <code>HEAD~3</code>. They seem similar. What are the differences?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,916
git
# What is the difference between HEAD^ and HEAD~ in Git? `HEAD^` (caret) and `HEAD~` (tilde) are both used to obtain a parent commit of `HEAD`. They can also end in numbers, e.g. `HEAD^2` and `HEAD~3`. They seem similar. What are the differences?
## Rules of thumb - `<rev>~<n>` goes backward *n* parents from *rev*, selecting the first parent each time. - Use `<rev>^<n>` to select the *n*-th immediate parent of merge commit *rev*. - Use `~` most of the time — to go back a number of generations and always choosing the first parent of merge commits, commonly what...
9069061
What effect does the `--no-ff` flag have for `git merge`?
1,371
2012-01-30 18:45:41
<p>Using <code>gitk log</code>, I could not spot a difference between the effect of <code>git merge</code> and <code>git merge --no-ff</code>. How can I observe the difference (with a git command or some tool)?</p>
883,157
1,162,226
2023-08-14 08:56:48
9,069,127
1,444
2012-01-30 18:51:29
582
2012-01-30 18:51:29
https://stackoverflow.com/q/9069061
https://stackoverflow.com/a/9069127
<p>The <code>--no-ff</code> flag prevents <code>git merge</code> from executing a "fast-forward" if it detects that your current <code>HEAD</code> is an ancestor of the commit you're trying to merge. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incom...
<p>The <code>--no-ff</code> flag prevents <code>git merge</code> from executing a "fast-forward" if it detects that your current <code>HEAD</code> is an ancestor of the commit you're trying to merge. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incom...
119, 717, 52842
fast-forward, git, merge
<h1>What effect does the `--no-ff` flag have for `git merge`?</h1> <p>Using <code>gitk log</code>, I could not spot a difference between the effect of <code>git merge</code> and <code>git merge --no-ff</code>. How can I observe the difference (with a git command or some tool)?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,917
git
# What effect does the `--no-ff` flag have for `git merge`? Using `gitk log`, I could not spot a difference between the effect of `git merge` and `git merge --no-ff`. How can I observe the difference (with a git command or some tool)?
The `--no-ff` flag prevents `git merge` from executing a "fast-forward" if it detects that your current `HEAD` is an ancestor of the commit you're trying to merge. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incoming commit. This commonly occurs whe...
14168677
Merge development branch with master
962
2013-01-05 04:45:48
<p>I have two branches namely <code>master</code> and <code>development</code> in a GitHub Repository. I am doing all my development in development branch as shown.</p> <pre><code>git branch development git add * git commit -m "My initial commit message" git push -u origin development </code></pre> <p>Now I want to ...
1,148,843
784,597
2022-05-19 12:10:34
14,168,817
1,443
2013-01-05 05:08:43
566,627
2017-03-08 21:40:21
https://stackoverflow.com/q/14168677
https://stackoverflow.com/a/14168817
<p>I generally like to merge <code>master</code> into the <code>development</code> first so that if there are any conflicts, I can resolve in the <code>development</code> branch itself and my <code>master</code> remains clean.</p> <pre><code>(on branch development)$ git merge master (resolve any merge conflicts if the...
<p>I generally like to merge <code>master</code> into the <code>development</code> first so that if there are any conflicts, I can resolve in the <code>development</code> branch itself and my <code>master</code> remains clean.</p> <pre><code>(on branch development)$ git merge master (resolve any merge conflicts if the...
119, 28897
git, git-merge
<h1>Merge development branch with master</h1> <p>I have two branches namely <code>master</code> and <code>development</code> in a GitHub Repository. I am doing all my development in development branch as shown.</p> <pre><code>git branch development git add * git commit -m "My initial commit message" git push -u origi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,918
git
# Merge development branch with master I have two branches namely `master` and `development` in a GitHub Repository. I am doing all my development in development branch as shown. ``` git branch development git add * git commit -m "My initial commit message" git push -u origin development ``` Now I want to merge all ...
I generally like to merge `master` into the `development` first so that if there are any conflicts, I can resolve in the `development` branch itself and my `master` remains clean. ``` (on branch development)$ git merge master (resolve any merge conflicts if there are any) git checkout master git merge development (the...
16736856
What should be in my .gitignore for an Android Studio project?
1,407
2013-05-24 14:04:16
<p>What files should be in my <code>.gitignore</code> for an Android Studio project?</p> <p>I've seen several examples that all include <code>.iml</code> but IntelliJ docs say that <code>.iml</code> must be included in your source control.</p>
569,143
109,306
2024-06-20 15:24:15
17,803,964
1,438
2013-07-23 07:29:34
444,324
2021-01-11 08:57:39
https://stackoverflow.com/q/16736856
https://stackoverflow.com/a/17803964
<p><strong>Updated to Android Studio 3.0</strong> Please share missing items in comments.</p> <p>A late answer but <a href="https://stackoverflow.com/questions/16640566/which-files-shouldnt-be-checked-in-into-version-control-in-android-studio">this</a> alternative answer was not right for us ...</p> <p>So, here's our g...
<p><strong>Updated to Android Studio 3.0</strong> Please share missing items in comments.</p> <p>A late answer but <a href="https://stackoverflow.com/questions/16640566/which-files-shouldnt-be-checked-in-into-version-control-in-android-studio">this</a> alternative answer was not right for us ...</p> <p>So, here's our g...
119, 25056, 91905
android-studio, git, gitignore
<h1>What should be in my .gitignore for an Android Studio project?</h1> <p>What files should be in my <code>.gitignore</code> for an Android Studio project?</p> <p>I've seen several examples that all include <code>.iml</code> but IntelliJ docs say that <code>.iml</code> must be included in your source control.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,919
git
# What should be in my .gitignore for an Android Studio project? What files should be in my `.gitignore` for an Android Studio project? I've seen several examples that all include `.iml` but IntelliJ docs say that `.iml` must be included in your source control.
**Updated to Android Studio 3.0** Please share missing items in comments. A late answer but [this](https://stackoverflow.com/questions/16640566/which-files-shouldnt-be-checked-in-into-version-control-in-android-studio) alternative answer was not right for us ... So, here's our gitignore file: ``` #built application ...
20195304
How do I update the password for Git?
1,023
2013-11-25 14:15:14
<p>I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (<em>thanks Adobe!</em>).</p> <p>Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (<code>Authentication failed for 'https://______.git'</code>), but I'm forgetting how to u...
1,619,973
1,368,904
2026-01-19 13:47:38
20,195,558
1,436
2013-11-25 14:27:41
1,368,904
2018-11-29 15:26:10
https://stackoverflow.com/q/20195304
https://stackoverflow.com/a/20195558
<p>To fix this on macOS, you can use </p> <pre><code>git config --global credential.helper osxkeychain </code></pre> <p>A username and password prompt will appear with your next Git action (pull, clone, push, etc.).</p> <p>For Windows, it's the same command with a different argument:</p> <pre><code>git config --glo...
<p>To fix this on macOS, you can use </p> <pre><code>git config --global credential.helper osxkeychain </code></pre> <p>A username and password prompt will appear with your next Git action (pull, clone, push, etc.).</p> <p>For Windows, it's the same command with a different argument:</p> <pre><code>git config --glo...
119, 369, 9847
change-password, git, macos
<h1>How do I update the password for Git?</h1> <p>I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (<em>thanks Adobe!</em>).</p> <p>Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (<code>Authentication failed for 'https://_...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,920
git
# How do I update the password for Git? I'm using BitBucket with Xcode and Git for version control, and recently I changed all of my passwords (*thanks Adobe!*). Unsurprisingly, I'm no longer able to push my local commits to my repository on BitBucket (`Authentication failed for 'https://______.git'`), but I'm forget...
To fix this on macOS, you can use ``` git config --global credential.helper osxkeychain ``` A username and password prompt will appear with your next Git action (pull, clone, push, etc.). For Windows, it's the same command with a different argument: ``` git config --global credential.helper wincred ```
9301782
Need to reset git branch to origin version
816
2012-02-15 21:33:52
<p>I was accidentally working on a branch I shouldn't have been for a while, so I branched off of it giving it the appropriate name. Now I want to overwrite the branch I shouldn't have been on to the version from origin (github). Is there an easy way to do this? I tried deleting the branch and then resetting up the ...
1,236,062
259,628
2025-09-02 19:08:27
9,302,259
1,430
2012-02-15 22:09:35
6,309
2019-08-30 12:10:06
https://stackoverflow.com/q/9301782
https://stackoverflow.com/a/9302259
<p>If you haven't pushed to origin yet, you can reset your branch to the <a href="https://stackoverflow.com/questions/2739376/definition-of-downstream-and-upstream/2749166#2749166">upstream</a> branch with:</p> <pre><code>git checkout mybranch git reset --hard origin/mybranch </code></pre> <p>(Make sure that you refe...
<p>If you haven't pushed to origin yet, you can reset your branch to the <a href="https://stackoverflow.com/questions/2739376/definition-of-downstream-and-upstream/2749166#2749166">upstream</a> branch with:</p> <pre><code>git checkout mybranch git reset --hard origin/mybranch </code></pre> <p>(Make sure that you refe...
119
git
<h1>Need to reset git branch to origin version</h1> <p>I was accidentally working on a branch I shouldn't have been for a while, so I branched off of it giving it the appropriate name. Now I want to overwrite the branch I shouldn't have been on to the version from origin (github). Is there an easy way to do this? I ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,921
git
# Need to reset git branch to origin version I was accidentally working on a branch I shouldn't have been for a while, so I branched off of it giving it the appropriate name. Now I want to overwrite the branch I shouldn't have been on to the version from origin (github). Is there an easy way to do this? I tried deleti...
If you haven't pushed to origin yet, you can reset your branch to the [upstream](https://stackoverflow.com/questions/2739376/definition-of-downstream-and-upstream/2749166#2749166) branch with: ``` git checkout mybranch git reset --hard origin/mybranch ``` (Make sure that you reference your latest commit in a separate...
48341920
Git branch command behaves like 'less'
826
2018-01-19 13:11:38
<p>When I use the <code>git branch</code> command to list all branches, I see the output of <code>git branch | less</code>.</p> <p>The command <code>git branch</code> is supposed to show a list of branches, like <code>ls</code> does for files.</p> <p>This is the output I get:</p> <p><a href="https://i.sstatic.net/rh4td...
105,591
2,331,735
2025-08-08 23:05:42
48,370,253
1,422
2018-01-21 18:30:49
2,514,383
2025-08-08 23:05:42
https://stackoverflow.com/q/48341920
https://stackoverflow.com/a/48370253
<p>As mentioned in <a href="https://stackoverflow.com/questions/48341920/git-branch-command-behaves-like-less#comment83670608_48342309">comments to Mark Adelsberger's answer</a>, this was a default behavior change <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/2.16.0.adoc?plain=1#L85-L88" rel="n...
<p>As mentioned in <a href="https://stackoverflow.com/questions/48341920/git-branch-command-behaves-like-less#comment83670608_48342309">comments to Mark Adelsberger's answer</a>, this was a default behavior change <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/2.16.0.adoc?plain=1#L85-L88" rel="n...
119, 391, 33345, 76220
git, git-branch, pager, terminal
<h1>Git branch command behaves like 'less'</h1> <p>When I use the <code>git branch</code> command to list all branches, I see the output of <code>git branch | less</code>.</p> <p>The command <code>git branch</code> is supposed to show a list of branches, like <code>ls</code> does for files.</p> <p>This is the output I ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,922
git
# Git branch command behaves like 'less' When I use the `git branch` command to list all branches, I see the output of `git branch | less`. The command `git branch` is supposed to show a list of branches, like `ls` does for files. This is the output I get: [![git branch paging output](https://i.sstatic.net/rh4td.pn...
As mentioned in [comments to Mark Adelsberger's answer](https://stackoverflow.com/questions/48341920/git-branch-command-behaves-like-less#comment83670608_48342309), this was a default behavior change [introduced in Git 2.16](https://github.com/git/git/blob/master/Documentation/RelNotes/2.16.0.adoc?plain=1#L85-L88). Yo...
2944469
How to commit my current changes to a different branch in Git
889
2010-05-31 15:26:26
<p>Sometimes it happens that I make some changes in my working directory, and I realize that these changes should be committed in a branch different to the current one. This usually happens when I want to try out new things or do some testing and I forget to create a new branch beforehand, but I don't want to commit di...
598,745
1,679
2021-06-17 20:16:02
2,945,904
1,409
2010-05-31 20:48:11
119,963
2019-12-04 13:08:41
https://stackoverflow.com/q/2944469
https://stackoverflow.com/a/2945904
<p>The other answers suggesting checking out the other branch, then committing to it, only work if the checkout is possible given the local modifications. If not, you're in the most common use case for <code>git stash</code>:</p> <pre><code>git stash git checkout other-branch git stash pop </code></pre> <p>The first ...
<p>The other answers suggesting checking out the other branch, then committing to it, only work if the checkout is possible given the local modifications. If not, you're in the most common use case for <code>git stash</code>:</p> <pre><code>git stash git checkout other-branch git stash pop </code></pre> <p>The first ...
119, 1879, 5597
branch, commit, git
<h1>How to commit my current changes to a different branch in Git</h1> <p>Sometimes it happens that I make some changes in my working directory, and I realize that these changes should be committed in a branch different to the current one. This usually happens when I want to try out new things or do some testing and I ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,923
git
# How to commit my current changes to a different branch in Git Sometimes it happens that I make some changes in my working directory, and I realize that these changes should be committed in a branch different to the current one. This usually happens when I want to try out new things or do some testing and I forget to...
The other answers suggesting checking out the other branch, then committing to it, only work if the checkout is possible given the local modifications. If not, you're in the most common use case for `git stash`: ``` git stash git checkout other-branch git stash pop ``` The first `stash` hides away your changes (basic...
1960799
How to use Git and Dropbox together?
1,133
2009-12-25 08:41:51
<p>Is it possible to use <a href="https://en.wikipedia.org/wiki/Git_%28software%29" rel="nofollow noreferrer">Git</a> and <a href="https://en.wikipedia.org/wiki/Dropbox_%28service%29" rel="nofollow noreferrer">Dropbox</a> together?</p>
322,012
235,246
2020-10-08 18:40:46
1,961,515
1,404
2009-12-25 17:10:40
50,924
2020-09-26 02:32:56
https://stackoverflow.com/q/1960799
https://stackoverflow.com/a/1961515
<p>I think that Git on Dropbox is great. I use it all the time. I have multiple computers (two at home and one at work) on which I use Dropbox as a central bare repository. Since I don’t want to host it on a public service, and I don’t have access to a server that I can always SSH to, Dropbox takes care of this by sync...
<p>I think that Git on Dropbox is great. I use it all the time. I have multiple computers (two at home and one at work) on which I use Dropbox as a central bare repository. Since I don’t want to host it on a public service, and I don’t have access to a server that I can always SSH to, Dropbox takes care of this by sync...
119, 17650
dropbox, git
<h1>How to use Git and Dropbox together?</h1> <p>Is it possible to use <a href="https://en.wikipedia.org/wiki/Git_%28software%29" rel="nofollow noreferrer">Git</a> and <a href="https://en.wikipedia.org/wiki/Dropbox_%28service%29" rel="nofollow noreferrer">Dropbox</a> together?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,924
git
# How to use Git and Dropbox together? Is it possible to use [Git](https://en.wikipedia.org/wiki/Git_%28software%29) and [Dropbox](https://en.wikipedia.org/wiki/Dropbox_%28service%29) together?
I think that Git on Dropbox is great. I use it all the time. I have multiple computers (two at home and one at work) on which I use Dropbox as a central bare repository. Since I don’t want to host it on a public service, and I don’t have access to a server that I can always SSH to, Dropbox takes care of this by syncing...
7167645
How do I create a new Git branch from an old commit?
787
2011-08-23 21:15:40
<blockquote> <p><strong>Possible Duplicate / a more recent/less clear question</strong> <br/> <a href="http://stackoverflow.com/questions/2816715/branch-from-a-previous-commit-using-git">Branch from a previous commit using Git</a></p> </blockquote> <p>I have a Git branch called <code>jzbranch</code> and have an ...
505,993
165,448
2020-12-03 17:01:35
7,167,659
1,392
2011-08-23 21:16:44
36,723
2020-12-03 17:01:35
https://stackoverflow.com/q/7167645
https://stackoverflow.com/a/7167659
<pre><code>git checkout -b NEW_BRANCH_NAME COMMIT_ID </code></pre> <p>This will create a new branch called 'NEW_BRANCH_NAME' and check it out.</p> <p>(&quot;check out&quot; means &quot;to switch to the branch&quot;)</p> <pre><code>git branch NEW_BRANCH_NAME COMMIT_ID </code></pre> <p>This just creates the new branch wi...
<pre><code>git checkout -b NEW_BRANCH_NAME COMMIT_ID </code></pre> <p>This will create a new branch called 'NEW_BRANCH_NAME' and check it out.</p> <p>(&quot;check out&quot; means &quot;to switch to the branch&quot;)</p> <pre><code>git branch NEW_BRANCH_NAME COMMIT_ID </code></pre> <p>This just creates the new branch wi...
119, 1879, 5597
branch, commit, git
<h1>How do I create a new Git branch from an old commit?</h1> <blockquote> <p><strong>Possible Duplicate / a more recent/less clear question</strong> <br/> <a href="http://stackoverflow.com/questions/2816715/branch-from-a-previous-commit-using-git">Branch from a previous commit using Git</a></p> </blockquote> <p...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,925
git
# How do I create a new Git branch from an old commit? > **Possible Duplicate / a more recent/less clear question** > [Branch from a previous commit using Git](http://stackoverflow.com/questions/2816715/branch-from-a-previous-commit-using-git) I have a Git branch called `jzbranch` and have an old commit id: `a9c14...
``` git checkout -b NEW_BRANCH_NAME COMMIT_ID ``` This will create a new branch called 'NEW_BRANCH_NAME' and check it out. ("check out" means "to switch to the branch") ``` git branch NEW_BRANCH_NAME COMMIT_ID ``` This just creates the new branch without checking it out. --- [in the comments many people seem to p...
2643502
How to solve Permission denied (publickey) error when using Git?
1,194
2010-04-15 07:46:34
<p>I'm on Mac Snow Leopard and I just installed <code>git</code>.</p> <p>I just tried </p> <pre><code>git clone git@thechaw.com:cakebook.git </code></pre> <p>but that gives me this error:</p> <pre><code>Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/` Permission denied (publickey). fat...
2,467,152
166,940
2025-12-26 08:14:59
2,643,584
1,391
2010-04-15 07:59:05
151,097
2021-07-19 11:01:39
https://stackoverflow.com/q/2643502
https://stackoverflow.com/a/2643584
<p><strong>If the user has not generated a ssh public/private key pair set before</strong></p> <p>This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)</p> <blockquote> <p>First start by setting up yo...
<p><strong>If the user has not generated a ssh public/private key pair set before</strong></p> <p>This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)</p> <blockquote> <p>First start by setting up yo...
119, 386, 25308, 57931
git, public-key, ssh, ssh-keys
<h1>How to solve Permission denied (publickey) error when using Git?</h1> <p>I'm on Mac Snow Leopard and I just installed <code>git</code>.</p> <p>I just tried </p> <pre><code>git clone git@thechaw.com:cakebook.git </code></pre> <p>but that gives me this error:</p> <pre><code>Initialized empty Git repository in `/U...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,926
git
# How to solve Permission denied (publickey) error when using Git? I'm on Mac Snow Leopard and I just installed `git`. I just tried ``` git clone git@thechaw.com:cakebook.git ``` but that gives me this error: ``` Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/` Permission denied (publ...
**If the user has not generated a ssh public/private key pair set before** This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.) > First start by setting up your own public/private key pair set. Thi...
2007662
Rollback to an old Git commit in a public repo
956
2010-01-05 17:01:14
<p>How can I go about rolling back to a specific commit in <strong>git</strong>?</p> <p>The best answer someone could give me was to use <code>git revert</code> X times until I reach the desired commit. </p> <p>So let's say I want to revert back to a commit that's 20 commits old, I'd have to run it 20 times. </p> ...
1,269,120
237,016
2024-08-30 02:06:20
2,007,704
1,390
2010-01-05 17:07:42
229,761
2018-08-19 08:32:39
https://stackoverflow.com/q/2007662
https://stackoverflow.com/a/2007704
<p>Try this:</p> <pre><code>git checkout [revision] . </code></pre> <p>where <code>[revision]</code> is the commit hash (for example: <code>12345678901234567890123456789012345678ab</code>). </p> <p>Don't forget the <code>.</code> at the end, very important. This will apply changes to the whole tree. You should execu...
<p>Try this:</p> <pre><code>git checkout [revision] . </code></pre> <p>where <code>[revision]</code> is the commit hash (for example: <code>12345678901234567890123456789012345678ab</code>). </p> <p>Don't forget the <code>.</code> at the end, very important. This will apply changes to the whole tree. You should execu...
119, 34403, 37230
git, git-checkout, git-revert
<h1>Rollback to an old Git commit in a public repo</h1> <p>How can I go about rolling back to a specific commit in <strong>git</strong>?</p> <p>The best answer someone could give me was to use <code>git revert</code> X times until I reach the desired commit. </p> <p>So let's say I want to revert back to a commit tha...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,927
git
# Rollback to an old Git commit in a public repo How can I go about rolling back to a specific commit in **git**? The best answer someone could give me was to use `git revert` X times until I reach the desired commit. So let's say I want to revert back to a commit that's 20 commits old, I'd have to run it 20 times. ...
Try this: ``` git checkout [revision] . ``` where `[revision]` is the commit hash (for example: `12345678901234567890123456789012345678ab`). Don't forget the `.` at the end, very important. This will apply changes to the whole tree. You should execute this command in the git project root. If you are in any sub direc...
3216360
Merge, update, and pull Git branches without using checkouts
911
2010-07-09 20:32:52
<p>I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do:</p> <pre><code>git merge origin/branchB </code></pre> <p>However, I would also like to keep a local copy of branch B, as I may occasionally check out the branch with...
252,569
9,900
2023-05-17 13:24:13
17,722,977
1,389
2013-07-18 12:06:05
null
2017-07-17 01:13:59
https://stackoverflow.com/q/3216360
https://stackoverflow.com/a/17722977
<h2>The Short Answer</h2> <p>As long as you're doing a <strong>fast-forward</strong> merge, then you can simply use</p> <pre><code>git fetch &lt;remote&gt; &lt;sourceBranch&gt;:&lt;destinationBranch&gt; </code></pre> <p>Examples:</p> <pre class="lang-bash prettyprint-override"><code># Merge local branch foo into local ...
<h2>The Short Answer</h2> <p>As long as you're doing a <strong>fast-forward</strong> merge, then you can simply use</p> <pre><code>git fetch &lt;remote&gt; &lt;sourceBranch&gt;:&lt;destinationBranch&gt; </code></pre> <p>Examples:</p> <pre class="lang-bash prettyprint-override"><code># Merge local branch foo into local ...
119, 28896, 28897, 37230
git, git-checkout, git-merge, git-pull
<h1>Merge, update, and pull Git branches without using checkouts</h1> <p>I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do:</p> <pre><code>git merge origin/branchB </code></pre> <p>However, I would also like to keep a l...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,928
git
# Merge, update, and pull Git branches without using checkouts I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do: ``` git merge origin/branchB ``` However, I would also like to keep a local copy of branch B, as I may o...
## The Short Answer As long as you're doing a **fast-forward** merge, then you can simply use ``` git fetch <remote> <sourceBranch>:<destinationBranch> ``` Examples: ``` # Merge local branch foo into local branch master, # without having to checkout master first. # Here `.` means to use the local repository as the ...
10940981
How to create a new branch from a tag?
855
2012-06-07 22:55:08
<p>I'd like to create a new master branch from an existing tag. Say I have a tag <code>v1.0</code>. How to create a new branch from this tag?</p>
728,605
48,523
2024-09-23 03:45:29
10,940,996
1,382
2012-06-07 22:57:40
48,523
2023-11-11 08:57:50
https://stackoverflow.com/q/10940981
https://stackoverflow.com/a/10940996
<p>Wow, that was easier than I thought:</p> <pre><code>git checkout -b newbranch v1.0 </code></pre> <hr /> <p>If running the above command you get an error</p> <blockquote> <p>warning: refname 'v1.0' is ambiguous. <br> fatal: ambiguous object name: 'v1.0'</p> </blockquote> <p>this is because you also have a branch with...
<p>Wow, that was easier than I thought:</p> <pre><code>git checkout -b newbranch v1.0 </code></pre> <hr /> <p>If running the above command you get an error</p> <blockquote> <p>warning: refname 'v1.0' is ambiguous. <br> fatal: ambiguous object name: 'v1.0'</p> </blockquote> <p>this is because you also have a branch with...
119, 60718, 76220
git, git-branch, git-tag
<h1>How to create a new branch from a tag?</h1> <p>I'd like to create a new master branch from an existing tag. Say I have a tag <code>v1.0</code>. How to create a new branch from this tag?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,929
git
# How to create a new branch from a tag? I'd like to create a new master branch from an existing tag. Say I have a tag `v1.0`. How to create a new branch from this tag?
Wow, that was easier than I thought: ``` git checkout -b newbranch v1.0 ``` --- If running the above command you get an error > warning: refname 'v1.0' is ambiguous. > fatal: ambiguous object name: 'v1.0' this is because you also have a branch with name `v1.0`. In this case specify `tags/` prefix: ``` git chec...
1895059
Revert to a commit by a SHA hash in Git?
761
2009-12-12 23:34:39
<p>I'm not clear on how <code>git revert</code> works. For example, I want to revert to a commit six commits behind the head, reverting all the changes in the intermediary commits in between.</p> <p>Say its <a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA</a> hash is <code>56e05fced214c44a37759efa2dfc...
839,903
103,739
2023-04-20 08:48:30
1,895,095
1,379
2009-12-12 23:51:36
19,563
2021-04-21 16:06:41
https://stackoverflow.com/q/1895059
https://stackoverflow.com/a/1895095
<p>If you want to commit on top of the current HEAD with the exact state at a different commit, undoing all the intermediate commits, then you can use <code>reset</code> to create the correct state of the index to make the commit.</p> <pre class="lang-bash prettyprint-override"><code># Reset the index and working tree ...
<p>If you want to commit on top of the current HEAD with the exact state at a different commit, undoing all the intermediate commits, then you can use <code>reset</code> to create the correct state of the index to make the commit.</p> <pre class="lang-bash prettyprint-override"><code># Reset the index and working tree ...
119, 34403
git, git-revert
<h1>Revert to a commit by a SHA hash in Git?</h1> <p>I'm not clear on how <code>git revert</code> works. For example, I want to revert to a commit six commits behind the head, reverting all the changes in the intermediary commits in between.</p> <p>Say its <a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,930
git
# Revert to a commit by a SHA hash in Git? I'm not clear on how `git revert` works. For example, I want to revert to a commit six commits behind the head, reverting all the changes in the intermediary commits in between. Say its [SHA](http://en.wikipedia.org/wiki/SHA-1) hash is `56e05fced214c44a37759efa2dfc25a65d8ae9...
If you want to commit on top of the current HEAD with the exact state at a different commit, undoing all the intermediate commits, then you can use `reset` to create the correct state of the index to make the commit. ``` # Reset the index and working tree to the desired tree # Ensure you have no uncommitted changes th...
1064499
How to list all Git tags?
1,000
2009-06-30 15:52:36
<p>In my repository, I have created tags using the following commands.</p> <pre class="lang-bash prettyprint-override"><code>git tag v1.0.0 -m 'finally a stable release' git tag v2.0.0 -m 'oops, there was still a major bug!' </code></pre> <p>How do you list all the tags in the repository?</p>
1,150,596
54,964
2024-02-02 15:32:01
1,064,505
1,368
2009-06-30 15:53:32
6,309
2024-02-02 15:32:01
https://stackoverflow.com/q/1064499
https://stackoverflow.com/a/1064505
<pre><code>git tag </code></pre> <p>should be enough. See <a href="http://git-scm.com/docs/git-tag" rel="noreferrer"><code>git tag</code> man page</a></p> <hr /> <p>You also have:</p> <pre><code>git tag -l &lt;pattern&gt; </code></pre> <blockquote> <p>List tags with names that match the given pattern (or all if no pat...
<pre><code>git tag </code></pre> <p>should be enough. See <a href="http://git-scm.com/docs/git-tag" rel="noreferrer"><code>git tag</code> man page</a></p> <hr /> <p>You also have:</p> <pre><code>git tag -l &lt;pattern&gt; </code></pre> <blockquote> <p>List tags with names that match the given pattern (or all if no pat...
119, 60718
git, git-tag
<h1>How to list all Git tags?</h1> <p>In my repository, I have created tags using the following commands.</p> <pre class="lang-bash prettyprint-override"><code>git tag v1.0.0 -m 'finally a stable release' git tag v2.0.0 -m 'oops, there was still a major bug!' </code></pre> <p>How do you list all the tags in the reposit...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,931
git
# How to list all Git tags? In my repository, I have created tags using the following commands. ``` git tag v1.0.0 -m 'finally a stable release' git tag v2.0.0 -m 'oops, there was still a major bug!' ``` How do you list all the tags in the repository?
``` git tag ``` should be enough. See [`git tag` man page](http://git-scm.com/docs/git-tag) --- You also have: ``` git tag -l <pattern> ``` > List tags with names that match the given pattern (or all if no pattern is given). > Typing "git tag" without arguments, also lists all tags. --- More recently ("[How to...
7539130
Go to a particular revision
913
2011-09-24 12:50:26
<p>I cloned a Git repository of a certain project. Can I turn the files to the initial state and when I review the files go to revision 2, 3, 4 ... most recent? I'd like to have an overview of how the project was evolving.</p>
1,223,126
653,379
2025-04-21 11:09:33
7,539,141
1,358
2011-09-24 12:52:51
9,990
2025-04-21 11:09:33
https://stackoverflow.com/q/7539130
https://stackoverflow.com/a/7539141
<p><strong>Before executing</strong> this command, keep in mind that it will leave you in a <strong>detached head state</strong>.</p> <p>Use <code>git checkout &lt;sha1&gt;</code> to check out a particular commit.</p> <p>Where <code>&lt;sha1&gt;</code> is the commit unique number (<a href="https://en.wikipedia.org/wiki...
<p><strong>Before executing</strong> this command, keep in mind that it will leave you in a <strong>detached head state</strong>.</p> <p>Use <code>git checkout &lt;sha1&gt;</code> to check out a particular commit.</p> <p>Where <code>&lt;sha1&gt;</code> is the commit unique number (<a href="https://en.wikipedia.org/wiki...
119, 1555, 69559
git, revision, revision-history
<h1>Go to a particular revision</h1> <p>I cloned a Git repository of a certain project. Can I turn the files to the initial state and when I review the files go to revision 2, 3, 4 ... most recent? I'd like to have an overview of how the project was evolving.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,932
git
# Go to a particular revision I cloned a Git repository of a certain project. Can I turn the files to the initial state and when I review the files go to revision 2, 3, 4 ... most recent? I'd like to have an overview of how the project was evolving.
**Before executing** this command, keep in mind that it will leave you in a **detached head state**. Use `git checkout <sha1>` to check out a particular commit. Where `<sha1>` is the commit unique number ([SHA-1](https://en.wikipedia.org/wiki/SHA-1) hash value) that you can obtain with `git log`. Here is what you co...
4220416
Can I specify multiple users for myself in .gitconfig?
1,137
2010-11-18 22:45:51
<p>In my <code>~/.gitconfig</code>, I list my personal email address under <code>[user]</code>, since that's what I want to use for Github repos.</p> <p>But, I've recently started using git for work, too. My company's git repo allows me to commit, but when it sends out announcements of new changesets, it says they are...
485,538
2,185
2025-09-27 07:48:36
4,220,493
1,354
2010-11-18 22:56:07
7,834
2015-08-25 11:04:03
https://stackoverflow.com/q/4220416
https://stackoverflow.com/a/4220493
<p>You can configure an individual repo to use a specific user / email address which overrides the global configuration. From the root of the repo, run</p> <pre><code>git config user.name "Your Name Here" git config user.email your@email.com </code></pre> <p>whereas the default user / email is configured in your ~/....
<p>You can configure an individual repo to use a specific user / email address which overrides the global configuration. From the root of the repo, run</p> <pre><code>git config user.name "Your Name Here" git config user.email your@email.com </code></pre> <p>whereas the default user / email is configured in your ~/....
119, 32868
git, git-config
<h1>Can I specify multiple users for myself in .gitconfig?</h1> <p>In my <code>~/.gitconfig</code>, I list my personal email address under <code>[user]</code>, since that's what I want to use for Github repos.</p> <p>But, I've recently started using git for work, too. My company's git repo allows me to commit, but whe...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,933
git
# Can I specify multiple users for myself in .gitconfig? In my `~/.gitconfig`, I list my personal email address under `[user]`, since that's what I want to use for Github repos. But, I've recently started using git for work, too. My company's git repo allows me to commit, but when it sends out announcements of new ch...
You can configure an individual repo to use a specific user / email address which overrides the global configuration. From the root of the repo, run ``` git config user.name "Your Name Here" git config user.email your@email.com ``` whereas the default user / email is configured in your ~/.gitconfig ``` git config --...
2452226
master branch and 'origin/master' have diverged, how to 'undiverge' branches'?
1,396
2010-03-16 05:05:40
<p>Somehow my <code>master</code> and my <code>origin/master</code> branch have diverged.<br /> I actually don't want them to diverge.</p> <p>How can I view these differences and <strong>merge</strong> them?</p>
1,596,474
209,320
2024-07-31 07:40:38
2,452,610
1,353
2010-03-16 07:02:23
6,309
2023-04-24 05:26:33
https://stackoverflow.com/q/2452226
https://stackoverflow.com/a/2452610
<p>You can <a href="https://stackoverflow.com/questions/53569/how-to-get-the-changes-on-a-branch-in-git">review the differences</a> with a:</p> <pre><code>git log HEAD..origin/main # old repositories git log HEAD..origin/master </code></pre> <p>before <a href="https://stackoverflow.com/questions/1484820/actually-pulli...
<p>You can <a href="https://stackoverflow.com/questions/53569/how-to-get-the-changes-on-a-branch-in-git">review the differences</a> with a:</p> <pre><code>git log HEAD..origin/main # old repositories git log HEAD..origin/master </code></pre> <p>before <a href="https://stackoverflow.com/questions/1484820/actually-pulli...
119, 1879
branch, git
<h1>master branch and 'origin/master' have diverged, how to 'undiverge' branches'?</h1> <p>Somehow my <code>master</code> and my <code>origin/master</code> branch have diverged.<br /> I actually don't want them to diverge.</p> <p>How can I view these differences and <strong>merge</strong> them?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,934
git
# master branch and 'origin/master' have diverged, how to 'undiverge' branches'? Somehow my `master` and my `origin/master` branch have diverged. I actually don't want them to diverge. How can I view these differences and **merge** them?
You can [review the differences](https://stackoverflow.com/questions/53569/how-to-get-the-changes-on-a-branch-in-git) with a: ``` git log HEAD..origin/main # old repositories git log HEAD..origin/master ``` before [pulling it](https://stackoverflow.com/questions/1484820/actually-pulling-with-git) (fetch + merge) (se...
29820791
Git - Ignore node_modules folder everywhere
695
2015-04-23 10:30:44
<p>I have a project containing multiple other projects : </p> <ul> <li>Main project <ul> <li>Mini project 1</li> <li>Mini project 2</li> </ul></li> </ul> <p>All containing <code>node_modules</code> folder. I want git to ignore the folder no matter where it is starting from the root folder. Something like this to add...
1,150,328
1,399,416
2025-04-09 14:45:07
29,820,869
1,352
2015-04-23 10:34:24
471,899
2021-09-26 17:11:40
https://stackoverflow.com/q/29820791
https://stackoverflow.com/a/29820869
<p>Add <code>node_modules/</code> or <code>node_modules</code> to the <code>.gitignore</code> file to ignore all directories called <code>node_modules</code> in the current folder and any subfolders like the below image.</p> <p><a href="https://i.sstatic.net/vPzT1.png" rel="noreferrer"><img src="https://i.sstatic.net/...
<p>Add <code>node_modules/</code> or <code>node_modules</code> to the <code>.gitignore</code> file to ignore all directories called <code>node_modules</code> in the current folder and any subfolders like the below image.</p> <p><a href="https://i.sstatic.net/vPzT1.png" rel="noreferrer"><img src="https://i.sstatic.net/...
119, 78230
git, node-modules
<h1>Git - Ignore node_modules folder everywhere</h1> <p>I have a project containing multiple other projects : </p> <ul> <li>Main project <ul> <li>Mini project 1</li> <li>Mini project 2</li> </ul></li> </ul> <p>All containing <code>node_modules</code> folder. I want git to ignore the folder no matter where it is star...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,935
git
# Git - Ignore node_modules folder everywhere I have a project containing multiple other projects : - Main project - Mini project 1 - Mini project 2 All containing `node_modules` folder. I want git to ignore the folder no matter where it is starting from the root folder. Something like this to add in .gitignore ...
Add `node_modules/` or `node_modules` to the `.gitignore` file to ignore all directories called `node_modules` in the current folder and any subfolders like the below image. [![example](https://i.sstatic.net/vPzT1.png)](https://i.sstatic.net/vPzT1.png)
1838873
Visualizing branch topology in Git
1,129
2009-12-03 09:55:04
<p>I'm playing with Git in isolation on my own machine, and I find it difficult to maintain a mental model of all my branches and commits. I know I can do a <code>git log</code> to see the commit history from where I am, but is there a way to see the entire branch topography, something like these ASCII maps that seem t...
823,558
11,410
2025-07-26 21:07:57
1,838,881
1,350
2009-12-03 09:56:27
8,457
2025-07-25 11:45:51
https://stackoverflow.com/q/1838873
https://stackoverflow.com/a/1838881
<p>Use <code>git log --graph</code> or <code>gitk</code>. (Both also accept <code>--all</code>, which will show all the branches instead of just the current one.)</p> <p>For branch names and a compact view, try:</p> <pre class="lang-none prettyprint-override"><code>git log --graph --decorate --oneline </code></pre>
<p>Use <code>git log --graph</code> or <code>gitk</code>. (Both also accept <code>--all</code>, which will show all the branches instead of just the current one.)</p> <p>For branch names and a compact view, try:</p> <pre class="lang-none prettyprint-override"><code>git log --graph --decorate --oneline </code></pre>
119
git
<h1>Visualizing branch topology in Git</h1> <p>I'm playing with Git in isolation on my own machine, and I find it difficult to maintain a mental model of all my branches and commits. I know I can do a <code>git log</code> to see the commit history from where I am, but is there a way to see the entire branch topography,...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,936
git
# Visualizing branch topology in Git I'm playing with Git in isolation on my own machine, and I find it difficult to maintain a mental model of all my branches and commits. I know I can do a `git log` to see the commit history from where I am, but is there a way to see the entire branch topography, something like thes...
Use `git log --graph` or `gitk`. (Both also accept `--all`, which will show all the branches instead of just the current one.) For branch names and a compact view, try: ``` git log --graph --decorate --oneline ```
8225125
Remove last commit from remote Git repository
571
2011-11-22 10:13:51
<p>How can I remove the last commit from a remote Git repository such as I don't see it any more in the log?</p> <p>If for example <code>git log</code> gives me the following commit history</p> <pre><code>A-&gt;B-&gt;C-&gt;D[HEAD, ORIGIN] </code></pre> <p>how can I go to</p> <pre><code>A-&gt;B-&gt;C[HEAD,ORIGIN] </code...
561,102
1,059,540
2025-03-25 10:42:41
8,225,166
1,348
2011-11-22 10:17:45
112,968
2025-03-25 10:42:41
https://stackoverflow.com/q/8225125
https://stackoverflow.com/a/8225166
<p>Be aware that this will create an &quot;alternate reality&quot; for people who have already fetched/pulled/cloned from the remote repository. But in fact, it's quite simple:</p> <pre class="lang-bash prettyprint-override"><code>git reset HEAD^ # remove commit locally git push origin +HEAD # force-push the new HEAD c...
<p>Be aware that this will create an &quot;alternate reality&quot; for people who have already fetched/pulled/cloned from the remote repository. But in fact, it's quite simple:</p> <pre class="lang-bash prettyprint-override"><code>git reset HEAD^ # remove commit locally git push origin +HEAD # force-push the new HEAD c...
119
git
<h1>Remove last commit from remote Git repository</h1> <p>How can I remove the last commit from a remote Git repository such as I don't see it any more in the log?</p> <p>If for example <code>git log</code> gives me the following commit history</p> <pre><code>A-&gt;B-&gt;C-&gt;D[HEAD, ORIGIN] </code></pre> <p>how can I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,937
git
# Remove last commit from remote Git repository How can I remove the last commit from a remote Git repository such as I don't see it any more in the log? If for example `git log` gives me the following commit history ``` A->B->C->D[HEAD, ORIGIN] ``` how can I go to ``` A->B->C[HEAD,ORIGIN] ```
Be aware that this will create an "alternate reality" for people who have already fetched/pulled/cloned from the remote repository. But in fact, it's quite simple: ``` git reset HEAD^ # remove commit locally git push origin +HEAD # force-push the new HEAD commit ``` If you want to still have it in your local reposito...
3311774
How to convert existing non-empty directory into a Git working directory and push files to a remote repository
863
2010-07-22 17:48:35
<ol> <li><p>I have a non-empty directory (eg /etc/something) with files that cannot be renamed, moved, or deleted.</p></li> <li><p>I want to check this directory into git in place.</p></li> <li><p>I want to be able to push the state of this repository to a remote repository (on another machine) using "git push" or some...
563,967
399,423
2025-02-18 14:19:13
3,311,824
1,347
2010-07-22 17:53:05
573
2025-02-18 14:19:13
https://stackoverflow.com/q/3311774
https://stackoverflow.com/a/3311824
<p>Given you've set up a git daemon on <code>&lt;url&gt;</code> and an empty repository:</p> <pre><code>cd &lt;localdir&gt; git init git add . git commit -m 'message' git remote add origin &lt;url&gt; git push -u origin master </code></pre>
<p>Given you've set up a git daemon on <code>&lt;url&gt;</code> and an empty repository:</p> <pre><code>cd &lt;localdir&gt; git init git add . git commit -m 'message' git remote add origin &lt;url&gt; git push -u origin master </code></pre>
119
git
<h1>How to convert existing non-empty directory into a Git working directory and push files to a remote repository</h1> <ol> <li><p>I have a non-empty directory (eg /etc/something) with files that cannot be renamed, moved, or deleted.</p></li> <li><p>I want to check this directory into git in place.</p></li> <li><p>I w...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,938
git
# How to convert existing non-empty directory into a Git working directory and push files to a remote repository 1. I have a non-empty directory (eg /etc/something) with files that cannot be renamed, moved, or deleted. 2. I want to check this directory into git in place. 3. I want to be able to push the state of this ...
Given you've set up a git daemon on `<url>` and an empty repository: ``` cd <localdir> git init git add . git commit -m 'message' git remote add origin <url> git push -u origin master ```
5129598
How to link a folder with an existing Heroku app
881
2011-02-26 20:39:34
<p>I have an existing Rails app on GitHub and deployed on Heroku. I'm trying to set up a new development machine and have cloned the project from my GitHub repository. However, I'm confused as to how to link this folder up to Heroku. Originally, I used the <code>heroku create</code> command, but obviously I don't want ...
291,281
1,574
2022-04-25 21:29:52
5,129,733
1,339
2011-02-26 21:03:05
62,082
2019-09-21 23:52:42
https://stackoverflow.com/q/5129598
https://stackoverflow.com/a/5129733
<p><a href="http://www.heroku.com" rel="noreferrer">Heroku</a> links your projects based on the <code>heroku</code> git remote (and a few other options, see the update below). To add your Heroku remote as a remote in your current repository, use the following command:</p> <pre><code>git remote add heroku git@heroku.co...
<p><a href="http://www.heroku.com" rel="noreferrer">Heroku</a> links your projects based on the <code>heroku</code> git remote (and a few other options, see the update below). To add your Heroku remote as a remote in your current repository, use the following command:</p> <pre><code>git remote add heroku git@heroku.co...
119, 8279
git, heroku
<h1>How to link a folder with an existing Heroku app</h1> <p>I have an existing Rails app on GitHub and deployed on Heroku. I'm trying to set up a new development machine and have cloned the project from my GitHub repository. However, I'm confused as to how to link this folder up to Heroku. Originally, I used the <code...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,940
git
# How to link a folder with an existing Heroku app I have an existing Rails app on GitHub and deployed on Heroku. I'm trying to set up a new development machine and have cloned the project from my GitHub repository. However, I'm confused as to how to link this folder up to Heroku. Originally, I used the `heroku create...
[Heroku](http://www.heroku.com) links your projects based on the `heroku` git remote (and a few other options, see the update below). To add your Heroku remote as a remote in your current repository, use the following command: ``` git remote add heroku git@heroku.com:project.git ``` where `project` is the name of you...
37972753
Git reset single file in feature branch to be the same as in master/main
676
2016-06-22 15:43:41
<p>I'm trying to revert my changes in a <strong>single file</strong> in my feature branch and I want this file to be the same as in master/main.</p> <p>I tried:</p> <pre><code>git checkout -- filename git checkout filename git checkout HEAD -- filename </code></pre> <p>It seems that none of these made any changes to m...
741,563
1,479,895
2025-06-24 15:29:53
37,972,822
1,334
2016-06-22 15:47:12
4,971,550
2025-03-05 22:20:29
https://stackoverflow.com/q/37972753
https://stackoverflow.com/a/37972822
<p>If you want to revert the file to its state in <code>master</code>:</p> <p><code>git checkout origin/master [filepath]</code></p> <p>Where <code>filepath</code> is the path to the file you want to revert. You can use relative paths for this command</p>
<p>If you want to revert the file to its state in <code>master</code>:</p> <p><code>git checkout origin/master [filepath]</code></p> <p>Where <code>filepath</code> is the path to the file you want to revert. You can use relative paths for this command</p>
119, 12309, 37230
git, git-checkout, revert
<h1>Git reset single file in feature branch to be the same as in master/main</h1> <p>I'm trying to revert my changes in a <strong>single file</strong> in my feature branch and I want this file to be the same as in master/main.</p> <p>I tried:</p> <pre><code>git checkout -- filename git checkout filename git checkout H...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,942
git
# Git reset single file in feature branch to be the same as in master/main I'm trying to revert my changes in a **single file** in my feature branch and I want this file to be the same as in master/main. I tried: ``` git checkout -- filename git checkout filename git checkout HEAD -- filename ``` It seems that non...
If you want to revert the file to its state in `master`: `git checkout origin/master [filepath]` Where `filepath` is the path to the file you want to revert. You can use relative paths for this command
7103631
How to unstage large number of files without deleting the content
642
2011-08-18 07:07:21
<p>I accidentally added a lot of temporary files using <code>git add -A</code></p> <p>I managed to unstage the files using the following commands and managed to remove the dirty index. </p> <pre><code>git ls-files -z | xargs -0 rm -f git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached </code></pre> <p...
384,442
59,249
2024-08-12 20:05:22
24,542,753
1,334
2014-07-02 23:37:41
316,798
2018-10-27 16:45:45
https://stackoverflow.com/q/7103631
https://stackoverflow.com/a/24542753
<h3><code>git reset</code></h3> <p>If all you want is to undo an overzealous "git add" run:</p> <pre><code>git reset </code></pre> <p>Your changes will be unstaged and ready for you to re-add as you please.</p> <hr> <p><strong>DO NOT RUN <code>git reset --hard</code>.</strong> </p> <p>It will not only unstage yo...
<h3><code>git reset</code></h3> <p>If all you want is to undo an overzealous "git add" run:</p> <pre><code>git reset </code></pre> <p>Your changes will be unstaged and ready for you to re-add as you please.</p> <hr> <p><strong>DO NOT RUN <code>git reset --hard</code>.</strong> </p> <p>It will not only unstage yo...
119, 456
git, version-control
<h1>How to unstage large number of files without deleting the content</h1> <p>I accidentally added a lot of temporary files using <code>git add -A</code></p> <p>I managed to unstage the files using the following commands and managed to remove the dirty index. </p> <pre><code>git ls-files -z | xargs -0 rm -f git diff ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,943
git
# How to unstage large number of files without deleting the content I accidentally added a lot of temporary files using `git add -A` I managed to unstage the files using the following commands and managed to remove the dirty index. ``` git ls-files -z | xargs -0 rm -f git diff --name-only --diff-filter=D -z | xargs ...
### `git reset` If all you want is to undo an overzealous "git add" run: ``` git reset ``` Your changes will be unstaged and ready for you to re-add as you please. --- **DO NOT RUN `git reset --hard`.** It will not only unstage your added files, but will revert any changes you made in your working directory. If y...
1270514
Undoing a 'git push'
857
2009-08-13 07:23:50
<p>Here's what I did on my <em>supposed-to-be-stable</em> branch...</p> <pre class="lang-bash prettyprint-override"><code>% git rebase master First, rewinding head to replay your work on top of it... Fast-forwarded alpha-0.3.0 to master. % git status # On branch alpha-0.3.0 # Your branch is ahead of 'origin/alpha-0.3....
1,372,466
109,362
2024-03-07 17:17:46
1,270,608
1,332
2009-08-13 07:47:35
19,563
2016-03-25 14:30:56
https://stackoverflow.com/q/1270514
https://stackoverflow.com/a/1270608
<p>You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.</p> <p>Then you need to 'force' push the old reference.</p> <pre><code>git push -f origin last_known_good_commit:br...
<p>You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.</p> <p>Then you need to 'force' push the old reference.</p> <pre><code>git push -f origin last_known_good_commit:br...
119, 28898
git, git-push
<h1>Undoing a 'git push'</h1> <p>Here's what I did on my <em>supposed-to-be-stable</em> branch...</p> <pre class="lang-bash prettyprint-override"><code>% git rebase master First, rewinding head to replay your work on top of it... Fast-forwarded alpha-0.3.0 to master. % git status # On branch alpha-0.3.0 # Your branch ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,944
git
# Undoing a 'git push' Here's what I did on my *supposed-to-be-stable* branch... ``` % git rebase master First, rewinding head to replay your work on top of it... Fast-forwarded alpha-0.3.0 to master. % git status # On branch alpha-0.3.0 # Your branch is ahead of 'origin/alpha-0.3.0' by 53 commits. # nothing to commi...
You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history. Then you need to 'force' push the old reference. ``` git push -f origin last_known_good_commit:branch_name ``` or in ...
6865302
Push local Git repo to new remote including all branches and tags
844
2011-07-28 20:33:35
<p>I have a local Git repo that I would like to push to a new remote repo (brand new repo set up on Beanstalk, if that matters).<br> My local repo has a few branches and tags, and I would like to keep all of my history. </p> <p>It looks like I basically just need to do a <code>git push</code>, but that only uploads t...
427,829
167,686
2025-09-13 09:52:05
6,865,367
1,329
2011-07-28 20:38:52
64,313
2025-09-13 09:52:05
https://stackoverflow.com/q/6865302
https://stackoverflow.com/a/6865367
<p>To push <a href="https://git-scm.com/docs/git-push#git-push---all" rel="noreferrer">all your branches</a>, use either (replace REMOTE with the name of the remote, for example &quot;origin&quot;):</p> <pre class="lang-bash prettyprint-override"><code>git push REMOTE '*:*' </code></pre> <p>or</p> <pre class="lang-bash...
<p>To push <a href="https://git-scm.com/docs/git-push#git-push---all" rel="noreferrer">all your branches</a>, use either (replace REMOTE with the name of the remote, for example &quot;origin&quot;):</p> <pre class="lang-bash prettyprint-override"><code>git push REMOTE '*:*' </code></pre> <p>or</p> <pre class="lang-bash...
119
git
<h1>Push local Git repo to new remote including all branches and tags</h1> <p>I have a local Git repo that I would like to push to a new remote repo (brand new repo set up on Beanstalk, if that matters).<br> My local repo has a few branches and tags, and I would like to keep all of my history. </p> <p>It looks like I...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,946
git
# Push local Git repo to new remote including all branches and tags I have a local Git repo that I would like to push to a new remote repo (brand new repo set up on Beanstalk, if that matters). My local repo has a few branches and tags, and I would like to keep all of my history. It looks like I basically just need...
To push [all your branches](https://git-scm.com/docs/git-push#git-push---all), use either (replace REMOTE with the name of the remote, for example "origin"): ``` git push REMOTE '*:*' ``` or ``` git push REMOTE --all ``` To push [all your tags](https://git-scm.com/docs/git-push#git-push---tags): ``` git push REMOT...
173919
Is there a "theirs" version of "git merge -s ours"?
1,166
2008-10-06 11:16:43
<p>When merging topic branch &quot;B&quot; into &quot;A&quot; using <code>git merge</code>, I get some conflicts. I know all the conflicts can be solved using the version in &quot;B&quot;.</p> <p>I am aware of <code>git merge -s ours</code>. But what I want is something like <code>git merge -s theirs</code>.</p> <p>Why...
756,220
1,277,510
2024-12-16 22:34:11
3,364,506
1,321
2010-07-29 15:58:58
102,401
2021-11-22 16:21:02
https://stackoverflow.com/q/173919
https://stackoverflow.com/a/3364506
<p>A similar alternative is the <code>--strategy-option</code> (short form <code>-X</code>) option, which accepts <code>theirs</code>. For example:</p> <pre><code>git checkout branchA git merge -X theirs branchB </code></pre> <p>However, this is more equivalent to <code>-X ours</code> than <code>-s ours</code>. The key...
<p>A similar alternative is the <code>--strategy-option</code> (short form <code>-X</code>) option, which accepts <code>theirs</code>. For example:</p> <pre><code>git checkout branchA git merge -X theirs branchB </code></pre> <p>However, this is more equivalent to <code>-X ours</code> than <code>-s ours</code>. The key...
119, 28897
git, git-merge
<h1>Is there a "theirs" version of "git merge -s ours"?</h1> <p>When merging topic branch &quot;B&quot; into &quot;A&quot; using <code>git merge</code>, I get some conflicts. I know all the conflicts can be solved using the version in &quot;B&quot;.</p> <p>I am aware of <code>git merge -s ours</code>. But what I want i...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,947
git
# Is there a "theirs" version of "git merge -s ours"? When merging topic branch "B" into "A" using `git merge`, I get some conflicts. I know all the conflicts can be solved using the version in "B". I am aware of `git merge -s ours`. But what I want is something like `git merge -s theirs`. Why doesn't it exist? How ...
A similar alternative is the `--strategy-option` (short form `-X`) option, which accepts `theirs`. For example: ``` git checkout branchA git merge -X theirs branchB ``` However, this is more equivalent to `-X ours` than `-s ours`. The key difference being that `-X` performs a regular recursive merge, resolving any co...
2941517
How to fix committing to the wrong Git branch?
841
2010-05-31 05:30:21
<p>I just made a perfectly good commit to the wrong branch. How do I undo the last commit in my master branch and then take those same changes and get them into my upgrade branch?</p>
267,252
130,006
2023-10-06 15:47:26
2,941,598
1,312
2010-05-31 05:53:20
230,575
2021-04-29 18:02:43
https://stackoverflow.com/q/2941517
https://stackoverflow.com/a/2941598
<p>If you haven't yet pushed your changes, you can also do a soft reset:</p> <pre><code>git reset --soft HEAD^ </code></pre> <p>This will revert the commit, but put the committed changes back into your index. Assuming the branches are relatively up-to-date with regard to each other, git will let you do a checkout into ...
<p>If you haven't yet pushed your changes, you can also do a soft reset:</p> <pre><code>git reset --soft HEAD^ </code></pre> <p>This will revert the commit, but put the committed changes back into your index. Assuming the branches are relatively up-to-date with regard to each other, git will let you do a checkout into ...
119, 53850
git, git-commit
<h1>How to fix committing to the wrong Git branch?</h1> <p>I just made a perfectly good commit to the wrong branch. How do I undo the last commit in my master branch and then take those same changes and get them into my upgrade branch?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,948
git
# How to fix committing to the wrong Git branch? I just made a perfectly good commit to the wrong branch. How do I undo the last commit in my master branch and then take those same changes and get them into my upgrade branch?
If you haven't yet pushed your changes, you can also do a soft reset: ``` git reset --soft HEAD^ ``` This will revert the commit, but put the committed changes back into your index. Assuming the branches are relatively up-to-date with regard to each other, git will let you do a checkout into the other branch, whereup...
1616957
How do you roll back (reset) a Git repository to a particular commit?
821
2009-10-24 04:22:27
<p>I cloned a Git repository and then tried to roll it back to a particular commit early on in the development process. Everything that was added to the repository after that point is unimportant to me so I want to omit all subsequent changes from my local source code.</p> <p>However, when I try to roll back in the GU...
863,411
null
2017-08-18 23:59:28
1,616,959
1,298
2009-10-24 04:24:35
964
2017-08-18 23:59:28
https://stackoverflow.com/q/1616957
https://stackoverflow.com/a/1616959
<pre><code>git reset --hard &lt;tag/branch/commit id&gt; </code></pre> <hr> <p><strong><em>Notes:</em></strong></p> <ul> <li><p><code>git reset</code> without the <code>--hard</code> option resets the commit history, but not the files. With the <code>--hard</code> option the files in working tree are also reset. (<a...
<pre><code>git reset --hard &lt;tag/branch/commit id&gt; </code></pre> <hr> <p><strong><em>Notes:</em></strong></p> <ul> <li><p><code>git reset</code> without the <code>--hard</code> option resets the commit history, but not the files. With the <code>--hard</code> option the files in working tree are also reset. (<a...
119
git
<h1>How do you roll back (reset) a Git repository to a particular commit?</h1> <p>I cloned a Git repository and then tried to roll it back to a particular commit early on in the development process. Everything that was added to the repository after that point is unimportant to me so I want to omit all subsequent change...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,950
git
# How do you roll back (reset) a Git repository to a particular commit? I cloned a Git repository and then tried to roll it back to a particular commit early on in the development process. Everything that was added to the repository after that point is unimportant to me so I want to omit all subsequent changes from my...
``` git reset --hard <tag/branch/commit id> ``` --- ***Notes:*** - `git reset` without the `--hard` option resets the commit history, but not the files. With the `--hard` option the files in working tree are also reset. ([credited user](https://stackoverflow.com/users/964/kauppi)) - If you wish to commit that state ...
1337320
How can I grep Git commits for a certain word?
881
2009-08-26 20:34:55
<p>In a Git code repository I want to list all commits that contain a certain word. I tried this</p> <pre class="lang-none prettyprint-override"><code>git log -p | grep --context=4 &quot;word&quot; </code></pre> <p>but it does not necessarily give me back the filename (unless it's less that five lines away from the wor...
283,532
109,305
2025-05-22 12:01:59
1,340,245
1,294
2009-08-27 10:41:39
46,058
2024-04-29 23:05:24
https://stackoverflow.com/q/1337320
https://stackoverflow.com/a/1340245
<p>If you want to find all commits where the <em>commit message</em> contains a given word, use</p> <pre class="lang-none prettyprint-override"><code>git log --grep=word </code></pre> <p>If you want to find all commits where &quot;word&quot; was added or removed in the <em>file contents</em> (to be more exact: where th...
<p>If you want to find all commits where the <em>commit message</em> contains a given word, use</p> <pre class="lang-none prettyprint-override"><code>git log --grep=word </code></pre> <p>If you want to find all commits where &quot;word&quot; was added or removed in the <em>file contents</em> (to be more exact: where th...
119, 816, 1271, 47913
git, git-log, grep, search
<h1>How can I grep Git commits for a certain word?</h1> <p>In a Git code repository I want to list all commits that contain a certain word. I tried this</p> <pre class="lang-none prettyprint-override"><code>git log -p | grep --context=4 &quot;word&quot; </code></pre> <p>but it does not necessarily give me back the file...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,951
git
# How can I grep Git commits for a certain word? In a Git code repository I want to list all commits that contain a certain word. I tried this ``` git log -p | grep --context=4 "word" ``` but it does not necessarily give me back the filename (unless it's less that five lines away from the word I searched for. I also...
If you want to find all commits where the *commit message* contains a given word, use ``` git log --grep=word ``` If you want to find all commits where "word" was added or removed in the *file contents* (to be more exact: where the number of occurrences of "word" changed), i.e., search the *commit contents*, use a so...
20101994
How to "git pull" from master into the development branch
921
2013-11-20 16:53:52
<p>I have a branch called &quot;dmgr2&quot; in development, and I want to pull from the master branch (live site) and incorporate all the changes into my development branch. Is there a better way to do this?</p> <p>Here is what I had planned on doing, after committing changes:</p> <pre><code>git checkout dmgr2 git pull...
2,111,791
975,243
2023-03-02 11:46:43
20,103,414
1,292
2013-11-20 17:58:31
1,256,452
2014-03-11 06:25:45
https://stackoverflow.com/q/20101994
https://stackoverflow.com/a/20103414
<p>The steps you listed will work, but there's a longer way that gives you more options:</p> <pre><code>git checkout dmgr2 # gets you "on branch dmgr2" git fetch origin # gets you up to date with origin git merge origin/master </code></pre> <p>The <code>fetch</code> command can be done at any point before...
<p>The steps you listed will work, but there's a longer way that gives you more options:</p> <pre><code>git checkout dmgr2 # gets you "on branch dmgr2" git fetch origin # gets you up to date with origin git merge origin/master </code></pre> <p>The <code>fetch</code> command can be done at any point before...
119, 1879, 4860
branch, git, pull
<h1>How to "git pull" from master into the development branch</h1> <p>I have a branch called &quot;dmgr2&quot; in development, and I want to pull from the master branch (live site) and incorporate all the changes into my development branch. Is there a better way to do this?</p> <p>Here is what I had planned on doing, a...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,952
git
# How to "git pull" from master into the development branch I have a branch called "dmgr2" in development, and I want to pull from the master branch (live site) and incorporate all the changes into my development branch. Is there a better way to do this? Here is what I had planned on doing, after committing changes: ...
The steps you listed will work, but there's a longer way that gives you more options: ``` git checkout dmgr2 # gets you "on branch dmgr2" git fetch origin # gets you up to date with origin git merge origin/master ``` The `fetch` command can be done at any point before the `merge`, i.e., you can swap the o...
16288176
Your branch is ahead of 'origin/master' by 3 commits
610
2013-04-29 21:01:58
<p>I am getting the following when running <code>git status</code>:</p> <pre><code>Your branch is ahead of 'origin/master' by 3 commits. </code></pre> <p>I have read that the way to fix this is to run <code>git pull --rebase</code> but what exactly is <code>rebase</code>? Will I lose data or is this a simple way to syn...
788,672
563,514
2025-09-04 06:03:19
16,288,283
1,285
2013-04-29 21:07:56
2,114,871
2024-09-02 08:08:28
https://stackoverflow.com/q/16288176
https://stackoverflow.com/a/16288283
<p>You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to &quot;solve&quot; it and it normally depends on how your workflow looks like:</p> <ul> <li>In a good workflow your remote copy of master should be the good one while your local copy of mast...
<p>You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to &quot;solve&quot; it and it normally depends on how your workflow looks like:</p> <ul> <li>In a good workflow your remote copy of master should be the good one while your local copy of mast...
119, 29934
git, git-rebase
<h1>Your branch is ahead of 'origin/master' by 3 commits</h1> <p>I am getting the following when running <code>git status</code>:</p> <pre><code>Your branch is ahead of 'origin/master' by 3 commits. </code></pre> <p>I have read that the way to fix this is to run <code>git pull --rebase</code> but what exactly is <code>...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,953
git
# Your branch is ahead of 'origin/master' by 3 commits I am getting the following when running `git status`: ``` Your branch is ahead of 'origin/master' by 3 commits. ``` I have read that the way to fix this is to run `git pull --rebase` but what exactly is `rebase`? Will I lose data or is this a simple way to sync ...
You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to "solve" it and it normally depends on how your workflow looks like: - In a good workflow your remote copy of master should be the good one while your local copy of master is just a copy of th...
4327708
git reset --hard HEAD leaves untracked files behind
834
2010-12-01 18:26:26
<p>When I run <code>git reset --hard HEAD</code>, it's supposed to reset to a pristine version of what you pulled, as I understand it. Unfortunately, it leaves files lying around, as a <code>git status</code> shows a big list of untracked files.</p> <p>How do you tell git "Just bring it back to EXACTLY what was in th...
379,447
377,446
2025-03-17 21:18:55
4,327,720
1,277
2010-12-01 18:28:19
112,968
2025-03-17 21:18:55
https://stackoverflow.com/q/4327708
https://stackoverflow.com/a/4327720
<p>You have to use <code>git clean -f -d</code> to get rid of untracked files and directories in your working copy. You can add <code>-x</code> to also remove ignored files, more info on that in <a href="https://stackoverflow.com/a/64966/6723250">this excellent SO answer</a>, and if you want to preview the changes you ...
<p>You have to use <code>git clean -f -d</code> to get rid of untracked files and directories in your working copy. You can add <code>-x</code> to also remove ignored files, more info on that in <a href="https://stackoverflow.com/a/64966/6723250">this excellent SO answer</a>, and if you want to preview the changes you ...
119
git
<h1>git reset --hard HEAD leaves untracked files behind</h1> <p>When I run <code>git reset --hard HEAD</code>, it's supposed to reset to a pristine version of what you pulled, as I understand it. Unfortunately, it leaves files lying around, as a <code>git status</code> shows a big list of untracked files.</p> <p>How ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,954
git
# git reset --hard HEAD leaves untracked files behind When I run `git reset --hard HEAD`, it's supposed to reset to a pristine version of what you pulled, as I understand it. Unfortunately, it leaves files lying around, as a `git status` shows a big list of untracked files. How do you tell git "Just bring it back to ...
You have to use `git clean -f -d` to get rid of untracked files and directories in your working copy. You can add `-x` to also remove ignored files, more info on that in [this excellent SO answer](https://stackoverflow.com/a/64966/6723250), and if you want to preview the changes you can use the `--dry-run` flag. If yo...
359424
Detach (move) subdirectory into separate Git repository
2,020
2008-12-11 13:57:03
<p>I have a Git repository which contains a number of subdirectories. Now I have found that one of the subdirectories is unrelated to the other and should be detached to a separate repository.</p> <p>How can I do this while keeping the history of the files within the subdirectory?</p> <p>I guess I could make a clone an...
334,571
23,896
2025-04-22 07:54:42
359,759
1,275
2008-12-11 15:40:54
23,356
2018-06-20 22:57:50
https://stackoverflow.com/q/359424
https://stackoverflow.com/a/359759
<p><strong>Update</strong>: This process is so common, that the git team made it much simpler with a new tool, <code>git subtree</code>. See here: <a href="https://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475">Detach (move) subdirectory into separate Git reposito...
<p><strong>Update</strong>: This process is so common, that the git team made it much simpler with a new tool, <code>git subtree</code>. See here: <a href="https://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475">Detach (move) subdirectory into separate Git reposito...
119, 46509, 68200
git, git-filter-branch, git-subtree
<h1>Detach (move) subdirectory into separate Git repository</h1> <p>I have a Git repository which contains a number of subdirectories. Now I have found that one of the subdirectories is unrelated to the other and should be detached to a separate repository.</p> <p>How can I do this while keeping the history of the file...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,955
git
# Detach (move) subdirectory into separate Git repository I have a Git repository which contains a number of subdirectories. Now I have found that one of the subdirectories is unrelated to the other and should be detached to a separate repository. How can I do this while keeping the history of the files within the su...
**Update**: This process is so common, that the git team made it much simpler with a new tool, `git subtree`. See here: [Detach (move) subdirectory into separate Git repository](https://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475) --- You want to clone your re...
7856416
View a file in a different Git branch without changing branches
918
2011-10-21 23:39:47
<p>Is it possible to open a file in a git branch without checking out that branch? How?</p> <p>Essentially I want to be able to open a file in my <a href="http://pages.github.com/" rel="noreferrer">GitHub Pages</a> branch without switching branches all the time. I don't want to modify it, just want to view it.</p>
253,586
147,390
2025-06-29 01:32:19
7,856,446
1,268
2011-10-21 23:47:30
460,542
2015-01-19 13:14:43
https://stackoverflow.com/q/7856416
https://stackoverflow.com/a/7856446
<p>This should work:</p> <pre><code>git show branch:file </code></pre> <p>Where <em>branch</em> can be any ref (branch, tag, HEAD, ...) and <em>file</em> is the full path of the file. To export it you could use</p> <pre><code>git show branch:file &gt; exported_file </code></pre> <p>You should also look at <a href="...
<p>This should work:</p> <pre><code>git show branch:file </code></pre> <p>Where <em>branch</em> can be any ref (branch, tag, HEAD, ...) and <em>file</em> is the full path of the file. To export it you could use</p> <pre><code>git show branch:file &gt; exported_file </code></pre> <p>You should also look at <a href="...
119, 456, 1879, 76220
branch, git, git-branch, version-control
<h1>View a file in a different Git branch without changing branches</h1> <p>Is it possible to open a file in a git branch without checking out that branch? How?</p> <p>Essentially I want to be able to open a file in my <a href="http://pages.github.com/" rel="noreferrer">GitHub Pages</a> branch without switching branche...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,956
git
# View a file in a different Git branch without changing branches Is it possible to open a file in a git branch without checking out that branch? How? Essentially I want to be able to open a file in my [GitHub Pages](http://pages.github.com/) branch without switching branches all the time. I don't want to modify it, ...
This should work: ``` git show branch:file ``` Where *branch* can be any ref (branch, tag, HEAD, ...) and *file* is the full path of the file. To export it you could use ``` git show branch:file > exported_file ``` You should also look at [VonC](https://stackoverflow.com/users/6309/vonc)'s answers to some related q...
7124726
git add only modified changes and ignore untracked files
943
2011-08-19 16:40:59
<p>I ran "git status" and listed below are some files that were modified/or under the heading "changes not staged for commit". It also listed some untracked files that I want to ignore (I have a ".gitignore" file in these directories).</p> <p>I want to put the modified files in staging so I can commit them. When I ra...
633,826
93,004
2023-09-29 11:48:57
7,124,760
1,258
2011-08-19 16:44:13
526,535
2021-07-15 12:26:09
https://stackoverflow.com/q/7124726
https://stackoverflow.com/a/7124760
<p>Ideally your <code>.gitignore</code> should prevent the untracked (and ignored) files from being shown in status, added using <code>git add</code> etc. So I would ask you to correct your <code>.gitignore</code></p> <p>You can do <code>git add -u</code> so that it will stage the modified and deleted files.</p> <p>You...
<p>Ideally your <code>.gitignore</code> should prevent the untracked (and ignored) files from being shown in status, added using <code>git add</code> etc. So I would ask you to correct your <code>.gitignore</code></p> <p>You can do <code>git add -u</code> so that it will stage the modified and deleted files.</p> <p>You...
119, 5597, 20002, 25056
commit, git, gitignore, staging
<h1>git add only modified changes and ignore untracked files</h1> <p>I ran "git status" and listed below are some files that were modified/or under the heading "changes not staged for commit". It also listed some untracked files that I want to ignore (I have a ".gitignore" file in these directories).</p> <p>I want to ...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,958
git
# git add only modified changes and ignore untracked files I ran "git status" and listed below are some files that were modified/or under the heading "changes not staged for commit". It also listed some untracked files that I want to ignore (I have a ".gitignore" file in these directories). I want to put the modified...
Ideally your `.gitignore` should prevent the untracked (and ignored) files from being shown in status, added using `git add` etc. So I would ask you to correct your `.gitignore` You can do `git add -u` so that it will stage the modified and deleted files. You can also do `git commit -a` to commit only the modified an...
62653114
How can I deal with this Git warning? "Pulling without specifying how to reconcile divergent branches is discouraged"
1,426
2020-06-30 08:18:57
<p>After a <code>git pull origin master</code>, I get the following message:</p> <pre><code>warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull: git config pull.rebase false # mer...
1,976,717
10,075,394
2025-05-03 01:18:07
62,653,400
1,255
2020-06-30 08:34:10
10,625,611
2024-07-11 13:04:25
https://stackoverflow.com/q/62653114
https://stackoverflow.com/a/62653400
<blockquote> <p>In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.</p> </blockquote> <p>When you do a <code>git pull origin master</code>, <br> <code>git pull</code> performs a merge, which often creates a merge commit. Therefore, by default, pulling from the remote is <em>not</e...
<blockquote> <p>In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.</p> </blockquote> <p>When you do a <code>git pull origin master</code>, <br> <code>git pull</code> performs a merge, which often creates a merge commit. Therefore, by default, pulling from the remote is <em>not</e...
119, 28896, 28897, 32868, 52842
fast-forward, git, git-config, git-merge, git-pull
<h1>How can I deal with this Git warning? "Pulling without specifying how to reconcile divergent branches is discouraged"</h1> <p>After a <code>git pull origin master</code>, I get the following message:</p> <pre><code>warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squel...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,959
git
# How can I deal with this Git warning? "Pulling without specifying how to reconcile divergent branches is discouraged" After a `git pull origin master`, I get the following message: ``` warning: Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one...
> In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD. When you do a `git pull origin master`, `git pull` performs a merge, which often creates a merge commit. Therefore, by default, pulling from the remote is *not* a harmless operation: it can create a new commit SHA hash valu...
10183724
List of remotes for a Git repository?
875
2012-04-17 00:58:00
<p>I have a Git repository. This repository has multiple remote repositories (I think). How can I get a list of the remote repositories that belong to said repository?</p> <p>Like <code>git list --remotes</code> or something like that?</p>
923,057
118,495
2023-03-03 10:11:49
10,183,740
1,253
2012-04-17 01:01:02
15,537
2023-03-03 10:11:49
https://stackoverflow.com/q/10183724
https://stackoverflow.com/a/10183740
<p>You can get a list of any configured remote URLs with the command:</p> <pre class="lang-bash prettyprint-override"><code>git remote -v </code></pre> <hr /> <p>This will give you something like the following:</p> <pre><code>base /home/***/htdocs/base (fetch) base /home/***/htdocs/base (push) origin git@bitbuck...
<p>You can get a list of any configured remote URLs with the command:</p> <pre class="lang-bash prettyprint-override"><code>git remote -v </code></pre> <hr /> <p>This will give you something like the following:</p> <pre><code>base /home/***/htdocs/base (fetch) base /home/***/htdocs/base (push) origin git@bitbuck...
119
git
<h1>List of remotes for a Git repository?</h1> <p>I have a Git repository. This repository has multiple remote repositories (I think). How can I get a list of the remote repositories that belong to said repository?</p> <p>Like <code>git list --remotes</code> or something like that?</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,960
git
# List of remotes for a Git repository? I have a Git repository. This repository has multiple remote repositories (I think). How can I get a list of the remote repositories that belong to said repository? Like `git list --remotes` or something like that?
You can get a list of any configured remote URLs with the command: ``` git remote -v ``` --- This will give you something like the following: ``` base /home/***/htdocs/base (fetch) base /home/***/htdocs/base (push) origin git@bitbucket.org:*** (fetch) origin git@bitbucket.org:*** (push) ```
11868447
How can I remove an entry in global configuration with git config?
720
2012-08-08 15:55:38
<p>I ran a global configuration command in <strong>git</strong> to exclude certain files using a <code>.gitignore_global</code> file:</p> <pre><code>git config --global core.excludesfile ~/.gitignore_global </code></pre> <p>Is there a way to undo the creation of this setting globally?</p>
959,870
143,476
2024-09-04 10:27:56
11,868,676
1,241
2012-08-08 16:08:34
147,356
2012-08-08 16:20:34
https://stackoverflow.com/q/11868447
https://stackoverflow.com/a/11868676
<p>I'm not sure what you mean by "undo" the change. You can remove the <code>core.excludesfile</code> setting like this:</p> <pre><code>git config --global --unset core.excludesfile </code></pre> <p>And of course you can simply edit the config file:</p> <pre><code>git config --global --edit </code></pre> <p>...and...
<p>I'm not sure what you mean by "undo" the change. You can remove the <code>core.excludesfile</code> setting like this:</p> <pre><code>git config --global --unset core.excludesfile </code></pre> <p>And of course you can simply edit the config file:</p> <pre><code>git config --global --edit </code></pre> <p>...and...
119
git
<h1>How can I remove an entry in global configuration with git config?</h1> <p>I ran a global configuration command in <strong>git</strong> to exclude certain files using a <code>.gitignore_global</code> file:</p> <pre><code>git config --global core.excludesfile ~/.gitignore_global </code></pre> <p>Is there a way to un...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,961
git
# How can I remove an entry in global configuration with git config? I ran a global configuration command in **git** to exclude certain files using a `.gitignore_global` file: ``` git config --global core.excludesfile ~/.gitignore_global ``` Is there a way to undo the creation of this setting globally?
I'm not sure what you mean by "undo" the change. You can remove the `core.excludesfile` setting like this: ``` git config --global --unset core.excludesfile ``` And of course you can simply edit the config file: ``` git config --global --edit ``` ...and then remove the setting by hand.
2706797
Finding what branch a Git commit came from
949
2010-04-25 01:23:33
<p>Is there a way to find out what branch a commit comes from given its <a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA-1</a> hash value? </p> <p>Bonus points if you can tell me how to accomplish this using Ruby Grit.</p>
443,506
2,066
2024-10-10 18:57:20
2,707,110
1,238
2010-04-25 04:07:22
119,963
2020-05-29 04:56:28
https://stackoverflow.com/q/2706797
https://stackoverflow.com/a/2707110
<p>While Dav is correct that the information isn't directly stored, that doesn't mean you can't ever find out. Here are a few things you can do.</p> <h1>Find branches the commit is on</h1> <pre><code>git branch -a --contains &lt;commit&gt; </code></pre> <p>This will tell you all branches which have the given commit ...
<p>While Dav is correct that the information isn't directly stored, that doesn't mean you can't ever find out. Here are a few things you can do.</p> <h1>Find branches the commit is on</h1> <pre><code>git branch -a --contains &lt;commit&gt; </code></pre> <p>This will tell you all branches which have the given commit ...
119
git
<h1>Finding what branch a Git commit came from</h1> <p>Is there a way to find out what branch a commit comes from given its <a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA-1</a> hash value? </p> <p>Bonus points if you can tell me how to accomplish this using Ruby Grit.</p>
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,962
git
# Finding what branch a Git commit came from Is there a way to find out what branch a commit comes from given its [SHA-1](http://en.wikipedia.org/wiki/SHA-1) hash value? Bonus points if you can tell me how to accomplish this using Ruby Grit.
While Dav is correct that the information isn't directly stored, that doesn't mean you can't ever find out. Here are a few things you can do. # Find branches the commit is on ``` git branch -a --contains <commit> ``` This will tell you all branches which have the given commit in their history. Obviously this is less...
2719579
How to add a changed file to an older (not last) commit in Git
789
2010-04-27 07:59:42
<p>I have changed several things over the last hour and committed them step by step, but I just realized I've forgot to add a changed file some commits ago (for example, the commit marked as <code>a0865...</code> below).</p> <p>The Log looks like this:</p> <pre><code>GIT TidyUpRequests u:1 d:0&gt; git log commit fc673...
230,139
26,462
2024-11-27 08:14:27
2,719,636
1,237
2010-04-27 08:10:25
893
2024-11-27 08:14:27
https://stackoverflow.com/q/2719579
https://stackoverflow.com/a/2719636
<p>Use <a href="http://git-scm.com/docs/git-rebase" rel="noreferrer"><code>git rebase</code></a>. Specifically:</p> <ol> <li>Use <code>git stash</code> to store the changes you want to add.</li> <li>Use <code>git rebase -i HEAD~10</code> (or however many commits back you want to see). Alternatively, use <code>git rebas...
<p>Use <a href="http://git-scm.com/docs/git-rebase" rel="noreferrer"><code>git rebase</code></a>. Specifically:</p> <ol> <li>Use <code>git stash</code> to store the changes you want to add.</li> <li>Use <code>git rebase -i HEAD~10</code> (or however many commits back you want to see). Alternatively, use <code>git rebas...
119, 29934
git, git-rebase
<h1>How to add a changed file to an older (not last) commit in Git</h1> <p>I have changed several things over the last hour and committed them step by step, but I just realized I've forgot to add a changed file some commits ago (for example, the commit marked as <code>a0865...</code> below).</p> <p>The Log looks like t...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,963
git
# How to add a changed file to an older (not last) commit in Git I have changed several things over the last hour and committed them step by step, but I just realized I've forgot to add a changed file some commits ago (for example, the commit marked as `a0865...` below). The Log looks like this: ``` GIT TidyUpReques...
Use [`git rebase`](http://git-scm.com/docs/git-rebase). Specifically: 1. Use `git stash` to store the changes you want to add. 2. Use `git rebase -i HEAD~10` (or however many commits back you want to see). Alternatively, use `git rebase -i commitHash^`. Replace `commitHash` with the hash of the commit you want to edit...
1778088
How do I clone a single branch in Git?
1,089
2009-11-22 07:21:19
<p>I have a local Git repository in <code>~/local_repo</code>. It has a few branches:</p> <pre><code>$ git branch * master rails c c++ </code></pre> <p>To clone the local repository, I do:</p> <pre><code>$ git clone ~/local_repo new_repo Initialized empty Git repository in /home/username/new_repo/.git/ </code></p...
1,095,757
66,450
2025-04-28 03:40:17
9,920,956
1,230
2012-03-29 07:34:01
6,309
2023-02-24 04:52:23
https://stackoverflow.com/q/1778088
https://stackoverflow.com/a/9920956
<p>Note: the <strong><a href="https://lkml.org/lkml/2012/3/28/418" rel="noreferrer">git1.7.10</a> (April 2012)</strong> actually allows you to <strong>clone only one branch</strong>:</p> <pre class="lang-bash prettyprint-override"><code># clone only the remote primary HEAD (default: origin/master) git clone &lt;url&gt...
<p>Note: the <strong><a href="https://lkml.org/lkml/2012/3/28/418" rel="noreferrer">git1.7.10</a> (April 2012)</strong> actually allows you to <strong>clone only one branch</strong>:</p> <pre class="lang-bash prettyprint-override"><code># clone only the remote primary HEAD (default: origin/master) git clone &lt;url&gt...
119, 1879, 34099
branch, git, git-clone
<h1>How do I clone a single branch in Git?</h1> <p>I have a local Git repository in <code>~/local_repo</code>. It has a few branches:</p> <pre><code>$ git branch * master rails c c++ </code></pre> <p>To clone the local repository, I do:</p> <pre><code>$ git clone ~/local_repo new_repo Initialized empty Git reposi...
q.PostTypeId = 1; a.PostTypeId = 2; EXISTS tag '%git%'; a.Body LIKE '%<code>%git%'; q.Score > 5; a.Score > 10
13,965
git
# How do I clone a single branch in Git? I have a local Git repository in `~/local_repo`. It has a few branches: ``` $ git branch * master rails c c++ ``` To clone the local repository, I do: ``` $ git clone ~/local_repo new_repo Initialized empty Git repository in /home/username/new_repo/.git/ ``` The `new_...
Note: the **[git1.7.10](https://lkml.org/lkml/2012/3/28/418) (April 2012)** actually allows you to **clone only one branch**: ``` # clone only the remote primary HEAD (default: origin/master) git clone <url> --single-branch # as in: git clone <url> --branch <branch> --single-branch <folder> ``` Note: - `<url>` is t...