当前位置: 首页 > 工具软件 > Git snippet > 使用案例 >

git basic

高钱青
2023-12-01

after you git clone and init; git remote add origin url

3 rules: git add git commit git push

        *.gitignore must unstage;

        * remove

        * remove local branch or remote branch

*if you already stage, you should "git rm -r --catched XX" create a git commit -m"" and git push

or you can delete local and git add -u and then commit push to update

**wq: exit

A Super Helpful Git Command!

I have a cool git command for you.

In your project, run this command to see a really nice log.

*git lg

 git checkout xxxfile (git log -> git checkout hashXX)

  1. git log --topo-order --all --graph --date=local --pretty=format:'%C(green)%h%C(reset) %><(55,trunc)%s%C(red)%d%C(reset) %C(blue)[%an]%C(reset) %C(yellow)%ad%C(reset)%n'

I've been using this really cool git command for a long time called git lg. It's like git log but wayyyyyyyy better.

Here's the free code snippet, and what your .gitconfig file would look like when you add it to your global git config

git lg - Coding For Everybody

Here's a preview of the new git log you'll create:

And here's what the default (and ugly, and hard to read) git log command usually looks like:

Happy coding!

  1. step: git add / 2. git commit -m”” / 3. git push 

*if u delete file use “git add -u”

/*git add .ignore?

Q2 How to delete files on remote github:??

git status then git add -u  then?  git commit /git push origin master

Q3 exit bash?  wq: enter

           Q4 git remove:  git rm -r --cached testi.js 

then git commit /git push 

4. git checkout xxxfile (git log -> git checkout hashXX)

Q5 https://www.freecodecamp.org/news/git-delete-branch-how-to-remove-a-local-or-remote-branch/

5. git branch

local:(

git branch

(git checkout branch_name

#where branch_name is the name of the branch you want to move to

#in my case the other branch I have is master, so I'd do:

#git checkout master) 

git branch -D local_branch_name)

remote:(

master

git push remote_name -d remote_branch_name

git branch -a

git push origin -d XXX

social-network-web % git push origin -d master

To https://github.com/sissixiyang/MERN-small-feature.git

 - [deleted]         master )

============git

(*directories name  have underscore instead of a dash)

(repo = repository which is the place to store your code)

(git --version

pwd

mkdir XXX   cd XXX)

sissiyang@sissiyangdeair myapp % git add app.js

sissiyang@sissiyangdeair myapp % git status    

On branch master

Changes to be committed:

  (use "git restore --staged <file>..." to unstage)

        modified:   app.js

 

sissiyang@sissiyangdeair myapp % git commit -m "initial commit"

[master bac4b35] initial commit

 1 file changed, 10 insertions(+)

but we havn’t ship it then: (“git”means exec git comma; origin:which branch;master: defaultcode in repo)

git push origin master

//clone copy

0.0 git clone url

           ls -la

                   ( .git :by default lots of  operating system will hidden anything start with a dot)

     Adding files and Staging them:

(“changes to be committed”: stage: file is inside ourbox that we’re about to ship over github)

myapp % git add app.js

myapp % git status  

(-m: message:””string)

myapp % git commit -m "initial commit"

[master bac4b35] initial commit

(but we havn’t ship it then:  “git”means exec git comma; origin:which branch;master: defaultcode in repo)

git remote add origin +URL 最开始就remote add 了?

git push origin master


 

—-gitignore

myapp % mkdir logs

myapp % echo hello > logs/dev.log

myapp % git status

social-network-web % echo logs/ > .gitignore

social-network-web % code .gitignore

*js

% git add .gitignore

% git commit -m "Add gitignore"

The rules in your .gitignore file only apply to untracked files. Since the files under that directory were already committed in your repository, you have to unstage them, create a commit, and push that to GitHub:

git rm -r --cached some-directory git commit -m 'Remove the now ignored directory "some-directory"' git push origin master

//delete files :  % git push -f origin main

—----

modified sth then

git status

git diff app.js (-red:that part is gone/vs +green:this part has added)

  1. git add sth 2.git push

git status (green files are ready tobe staged)

—-after modified

myapp % git commit -m "Second commit"

  1. git commit -m"Second commit" 

[master 4bf4d41] Second commit

 7 files changed, 1449 insertions(+), 28070 deletions(-)

 create mode 100644 .env

 create mode 100644 logs/dev.log

 create mode 100644 public/index.html

sissiyang@sissiyangdeair myapp % git status

On branch master

nothing to commit, working tree clean

  1. sissiyang@sissiyangdeair myapp % git push origin master

Q1 fatal: 'origin' does not appear to be a git repository

fatal: Could not read from remote repository.You haven't set up a remote. remote. 

run git remote add origin <URL to remote repo>, then try to push again.


 

0. myapp % git remote add origin +URLhttps://github.com/sissixiyang/MERN-small-feature.git

myapp % git push origin master 

 类似资料:

相关阅读

相关文章

相关问答