atlaschiew / git-study Goto Github PK
View Code? Open in Web Editor NEWhappy giting
happy giting
The git checkout
command creates, and switches branches, restores and undo changes from commit; however, git switch
only creates and switches branches. Git switch
and git checkout
let you create and move into a branch.
git checkout <hash> -- <file1> <file2>
Stash is just a convenience method. Since branches are so cheap and easy to manage in git, I personally almost always prefer creating a new temporary branch than stashing, but it's a matter of taste mostly.
The one place I do like stashing is if I discover I forgot something in my last commit and have already started working on the next one in the same branch:
# Assume the latest commit was already done
# start working on the next patch, and discovered I was missing something
# stash away the current mess I made
git stash save
# some changes in the working dir
# and now add them to the last commit:
git add -u
git commit --amend
# back to work!
git stash pop
First, create a new local branch and check it out:
git checkout -b <branch-name>
The remote branch is automatically created when you push it to the remote server:
git push <remote-name> <branch-name>
is typically origin, which is the name which git gives to the remote you cloned from. Your colleagues may then simply pull that branch.
Note however that formally, the format is:
git push <remote-name> <local-branch-name>:<remote-branch-name>
But when you omit one, it assumes both branch names are the same. Having said this, as a word of caution, do not make the critical mistake of specifying only : (with the colon), or the remote branch will be deleted!
It's important to understand that git revert undoes a single commit—it does not "revert" back to the previous state of a project by removing all subsequent commits. In Git, this is actually called a reset, not a revert.
git pull
will merge the conflicted files into ur local copy. For safety, we can use git fetch
to check the change.
preview git pull
# preview git pull
git fetch -v
git log -p HEAD..origin/main
git diff HEAD..origin/main
# apply the changes by merge..
git merge origin/main
# .. or just pull the changes
git pull
git pull --rebase origin master
If you know you want to use git reset, it still depends what you mean by "uncommit". If all you want to do is undo the act of committing, leaving everything else intact, use:
git reset --soft HEAD^
If you want to undo the act of committing and everything you'd staged, but leave the work tree (your files) intact:
git reset HEAD^
And if you actually want to completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit (as the original question asked):
git reset --hard HEAD^
The original question also asked it's HEAD^ not HEAD. HEAD refers to the current commit - generally, the tip of the currently checked-out branch. The ^ is a notation which can be attached to any commit specifier, and means "the commit before". So, HEAD^ is the commit before the current one, just as master^ is the commit before the tip of the master branch.
Here's the portion of the git-rev-parse documentation describing all of the ways to specify commits (^ is just a basic one among many).
solution is in here https://confluence.atlassian.com/bbkb/why-am-i-not-prompted-for-password-when-pushing-or-pulling-to-my-repositories-in-bitbucket-cloud-via-https-800293400.html
must run power shell as administrator, then execute command below.
git config --system --unset credential.helper
git config --global --unset credential.helper
git config --local --unset credential.helper
In Git, HEAD refers to the currently checked-out branch’s latest commit. However, in a detached HEAD state, the HEAD does not point to any branch, but a specific commit or the remote repository.
#create a new repository on the command line
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/atlaschiew/git.git
git push -u origin main
#push an existing repository from the command line
git remote set-url origin https://github.com/atlaschiew/git.git
git branch -M main
git push -u origin main
You can have multiple remotes, each with a different name - such as the default "origin" through git remote add
Your question makes the assumption that you currently have the master branch checked out.
git push -u origin master
Push the local branch named master to the "origin" remote as the branch named master. The -u flag tells local git to track that remote branch as upstream to your local branch.
check commit history
git log
show details of commit
git show <hash>
git pull --rebase
is a shorthand for git fetch
and then a plain git rebase
, as opposed as to the default git merge
. The practical difference is that applying only the latter would not fetch any new commits from your remote prior to rebasing your code on top of, as it would only take into account what your local repository's already aware of.
It's also worth mentioning that merging conflicts would appear in the same way as a regular git pull.
git restore --staged <file>
git checkout -b <branch_name>
or
git switch -c <branch_name>
git branch -r
git branch
git branch -a
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.