Difference between revisions of "Using Git"

From Apertium
Jump to navigation Jump to search
(git stash is probably the simplest)
Line 1: Line 1:
==Removing/undoing your changes to a file==
+
==Removing/undoing all changes since the last commit==
  +
<pre>
  +
git stash
  +
</pre>
  +
If you've added new files to be committed, the're "unadded" (but not deleted); if you've made changes to tracked files, the changes are removed so they look like what they were in the last commit. (Bonus point: removed changes can be re-added with <code>git stash pop</code>.)
  +
  +
This only works on ''all'' changes (you can't stash a specific file).
  +
  +
==Removing/undoing your changes to a certain file / path==
 
<pre>
 
<pre>
 
git checkout -- <path>
 
git checkout -- <path>
 
</pre>
 
</pre>
   
If "path" is ".", you undo all your changes to version controlled files:
+
If "path" is ".", you undo all your changes to version controlled files in that directory and sub-directories:
 
<pre>
 
<pre>
 
git checkout -- .
 
git checkout -- .
 
</pre>
 
</pre>
   
 
If you've first done <code>git add</code> (to "stage your changes", so some file is listed under <code>Changes to be committed</code>), you first need to do <code>git reset</code> to unstage the changes, then checkout in case you had changes to files already tracked. So to do that for the whole dir:
 
Note: if you've first done <code>git add</code> (to "stage your changes", so some file is listed under <code>Changes to be committed</code>), you first need to do <code>git reset</code> to unstage the changes, then checkout:
 
 
<pre>
 
<pre>
 
git reset HEAD .
 
git reset HEAD .

Revision as of 18:47, 3 October 2013

Removing/undoing all changes since the last commit

git stash

If you've added new files to be committed, the're "unadded" (but not deleted); if you've made changes to tracked files, the changes are removed so they look like what they were in the last commit. (Bonus point: removed changes can be re-added with git stash pop.)

This only works on all changes (you can't stash a specific file).

Removing/undoing your changes to a certain file / path

 git checkout -- <path>

If "path" is ".", you undo all your changes to version controlled files in that directory and sub-directories:

 git checkout -- .

If you've first done git add (to "stage your changes", so some file is listed under Changes to be committed), you first need to do git reset to unstage the changes, then checkout in case you had changes to files already tracked. So to do that for the whole dir:

git reset HEAD .
git checkout -- .

Merge conflict: Throw away local changes

 git checkout master <path>
 git commit
 git merge master

(The last command should now do nothing, just say you're fully merged.)