User Tools

Site Tools


software:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
software:git [2018/04/09 23:54]
dave
software:git [2018/09/24 14:19] (current)
dave
Line 1: Line 1:
 ====== git == ====== git ==
  
-Just your ordinary overly complicated* version control system.+Git is just your ordinary overly complicated* version control system. ​ ​I'​m really great at //doing// stuff with ''​git'',​ especially things I didn't intend! ​ :) 
  
-===== How to do stuff ==+Here's a useful collection of ways to get yourself out of your own self-created git jams.
  
-==== How to revert ​a single file ==+===== How To Undo Stuff == 
 + 
 +==== Revert ​a single file ==
  
 <​code>​ <​code>​
Line 13: Line 15:
 And near the top of the output are instructions. And near the top of the output are instructions.
  
-==== How to revert ​changes made to local copy ==  +==== Revert ​changes made to local copy ==  
-**THERE IS NO CONFIRMATION PROMPT!  ​DO NOT DO THIS UNTLESS YOU REALLY MEAN IT!**+**Warning: ​ there is no confirmation prompt!  ​Don't type this unless you really mean bring your local copy back in sync with the current branch!**
 <​code>​ <​code>​
 git checkout . git checkout .
 +</​code>​
 +
 +==== Unstage a staged file or directory == 
 +From [[https://​stackoverflow.com/​questions/​348170/​how-to-undo-git-add-before-commit|stackoverflow.]]
 +
 +<​code>​
 +  git reset <​path-to-file-or-dir>​
 +</​code>​
 +
 +==== Change a previous commit ==
 +
 +If you haven'​t pushed it yet, it is possible to make a new commit that is automatically merged with the previous commit. ​ Stage the changes you need to add to the previous commit with ''​git add''​ first, then:
 +
 +<​code>​
 +git commit --amend
 +</​code>​
 +
 +This command will open ''​$EDITOR''​ for editing of the commit message and then merge the staged changes with the previous commit. ​ To avoid editing the commit message, include ''​--no-edit''​.
 +
 +==== Undo the previous commit ==
 +
 +<​code>​
 +git commit -m "​Something terribly misguided" ​           ​
 +# oops! 
 +
 +# this line reverts the previous commit ​
 +git reset HEAD~                                       
 +</​code>​
 +
 +===== Other Useful Notes ==
 +
 +==== Get a diff including all the changes between two revisions ==
 +
 +<​code>​
 +git diff <​rev1>​^..<​rev2>​
 +</​code>​
 +
 +==== Merge Squash == 
 +
 +<​code>​
 +git merge --squash <​other_branch>​
 +</​code>​
 +
 +Applies all of the changes made to ''<​other_branch>''​ to the working copy as a single set of //staged// changes which is ready to be committed. ​ Use ''​git commit''​ as per usual.
 +
 +==== List Remote Branches ==
 +
 +After initially cloning a repository, git is only aware of the the default branch, which is usually ''​master''​.
 +
 +<​code>​
 +$git branch
 +* master
 +</​code>​
 +
 +Use ''​-a''​ to list remote branches:
 +
 +<​code>​
 +$git branch -a
 +* master
 +remotes/​origin/​HEAD -> origin/​master
 +remotes/​origin/​release
 +</​code>​
 +
 +===== Misc Tasks ==
 +
 +==== Show only the files that are modified as a commit ==
 +
 +This removes the diff lines from the ''​show''​ command (''​+''/''​-''​ lines):
 +
 +<​code>​
 +$git show <​hash>​ --name-only
 </​code>​ </​code>​
  
 //*Compared to other version control systems.// //*Compared to other version control systems.//
 +
 +
software/git.1523343241.txt.gz · Last modified: 2018/04/09 23:54 by dave