Skip to content

Instantly share code, notes, and snippets.

@hugo53
Last active December 29, 2015 05:49
Show Gist options
  • Save hugo53/7625048 to your computer and use it in GitHub Desktop.
Save hugo53/7625048 to your computer and use it in GitHub Desktop.
Git manually

Committed commit A, but not pushed A. Want to delete the commit A because of some reasons.

git reset --hard HEAD^

When use cocoapods, must have a tag. Therefore, must create tag

git tag 1.0.0[tag version] -a

[Enter tag message, must do!]

git push origin --tags

Edit comment for the lastest commit

Unpushed Commit

Just do

git commit --amend -m "Fifth commit. Nothing at all! I known happiness is waiting"

After that, pushing it or edit commit comment again, so still must pushing it :v!

Pushed Commit

First

git commit --amend -m "Fifth commit. Nothing at all! I known happiness is waiting"

And then

git push --force  //Must do, I forgot this, and see nothing change in hub. Wonder why? :v, unpushed, why can see :v!

Stash

git stash

Get stash list

git stash list

Apply lastest stash

git stash apply

Discard change

git checkout -- filePath/fileName

Merge PR but have conflict

git checkout -b cwagdev-patch-1 master // (cwagdev-patch-1 is patch version which sent by PR)
git pull https://github.com/cwagdev/iLL.git patch-1 // After change branch (now is cwagdev-patch-1 branch), must pull it
// Then, resolve conflict manually
// After conflicts are resolved, must commit
git commit -a -m "Removed ASIHTTPRequest via cwagdev PR" // Now, still on cwagdev-patch-1 branch
git checkout master // back to master branch
git merge cwagdev-patch-1 // merge cwagdev-patch-1 branch to master branch
git push origin master // push merged code to master
// DONE

Discard all uncommited changes

git reset --hard HEAD
git clean -fdx    // To remove all untracked files

Git Adding

git add -A  // stages All
git add .   // stages new and modified, without deleted
git add -u  // stages modified and deleted, without new
Added all untracked files (new files), modified files, deleted files
git add -A . // equivalent git add . +  git add -u

Fetch origin

git fetch origin -v

localhost:CodeSnippets$ git fetch origin -v
From https://github.com/hugo53/iCodeSnippets
 = [up to date]      master     -> origin/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment